El vie, 22-02-2002 a las 04:54, jas escribi�:
> I don't know what it is but I am having a hell of a time trying to get some
> results of a query setup into an array or variable (too much of a newbie to
> know which) that can be passed to a confirmation page before deleting the
> record from a table. I have given up working on this but for those of you
> that want to finish it here is the code and the table structure...
Recomendation 1:
Use JavaScript instead of create a confirmation page... (for speed
reasons!)
Eg:
<html>
<head>
<script language="JavaScript">
function confirmDelete(form){
if (confirm("Do you really want to delete this record?")){
form.action = form.action + "?delete=1";
form.submit();
}
}
</script>
</head>
<body>
<form name=myForm action="myScript.php" method="post">
<input type="button" name="delete" value="delete"
onClick="confirmDelete(myForm)">
</form>
</body>
</html>
>
> [Table Structure]
> id int(30) DEFAULT '0' NOT NULL auto_increment,
> car_type varchar(30),
> car_model varchar(30),
> car_year varchar(15),
> car_price varchar(15),
> car_vin varchar(25),
> dlr_num varchar(25),
> PRIMARY KEY (id)
>
> [Page 1 - Queries DB table for records]
> <?php
> require '../path/to/db.php';
> $result = @mysql_query("SELECT * FROM cur_inv",$dbh) or die("Could not
> execute query, please try again later");
> echo "<table border=\"0\" class=\"table-body\" width=\"100%\"><form
> name=\"rem_inv\" method=\"post\" action=\"rem_conf.php3\">
> <tr><td align=\"center\" colspan=\"3\"><font size=\"4\"><B>Current
> Inventory</B></font><hr color=\"333333\"></td></tr>";
> $count = -1;
> while ($myrow = mysql_fetch_array($result)) {
> $id = $row["id"];
> $car_type = $row["car_type"];
> $car_model = $row["car_model"];
> $car_year = $row["car_year"];
> $car_price = $row["car_price"];
> $car_vin = $row["car_vin"];
> $count ++;
> echo "<tr><td width=\"30%\"><B>Type Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_type"));
> echo "</td><td><input type=\"checkbox\" name=\"id[]\"
> value=\"".$myrow[id]."\">remove</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>Model Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_model"));
> echo "</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>Year Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_year"));
> echo "</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>Price Of Car: </B></td><td>$";
> printf(mysql_result($result,$count,"car_price"));
> echo "</td></tr>\n";
> echo "<tr><td width=\"30%\"><B>VIN Of Car: </B></td><td>";
> printf(mysql_result($result,$count,"car_vin"));
> echo "</td></tr><tr><td colspan=\"3\"><hr color=\"333333\"></td></tr>\n";
> }
> echo "<tr><td><input type=\"submit\" name=\"delete\"
> value=\"delete\"></td></tr></form></table>";
> ?>
>
> [Page 2 - Takes records and confirms which ones to be deleted]
> <?php
> print("
> <table border=\"0\" class=\"table-body\" width=\"100%\">
> <form name=\"rem_inv\" method=\"post\" action=\"done2.php3\">
> <INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">
> <INPUT TYPE=\"hidden\" NAME=\"car_type\" VALUE=\"$car_type\">
> <INPUT TYPE=\"hidden\" NAME=\"car_model\" VALUE=\"$car_model\">
> <INPUT TYPE=\"hidden\" NAME=\"car_year\" VALUE=\"$car_year\">
> <INPUT TYPE=\"hidden\" NAME=\"car_price\" VALUE=\"$car_price\">
> <INPUT TYPE=\"hidden\" NAME=\"car_vin\" VALUE=\"$car_vin\">
> <tr>
> <td align=\"center\" colspan=\"3\"><font size=\"4\"><B>Confirm Record
> Deletion</B></font><hr color=\"333333\"></td>
> </tr>
> <tr>
> <td width=\"30%\"><B>Type Of Car: </B></td>
> <td>$car_type</td>
> </tr>
> <tr>
> <td width=\"30%\"><B>Model Of Car: </B></td>
> <td>$car_model</td>
> </tr>
> <tr>
> <td width=\"30%\"><B>Year Of Car: </B></td>
> <td>$car_year</td>
> </tr>
> <tr>
> <td width=\"30%\"><B>Price Of Car: </B></td>
> <td>$car_price</td>
> </tr>
> <tr>
> <td width=\"30%\"><B>VIN Of Car: </B></td>
> <td>$car_vin</td>
> </tr>
> <tr>
> <td colspan=\"3\"><hr color=\"333333\"></td>
> </tr>
> <tr>
> <td><input type=\"submit\" name=\"delete\" value=\"delete\"></td>
> </tr>
> </form>
> </table>");
> ?>
>
> [Page 3 - Connects to DB and deletes selected records]
> <?php
> require '../path/to/db.php';
> $table_name = "cur_inv";
> $sql = "DELETE FROM $table_name WHERE id = '$id'";
> echo($sql);
> $result = mysql_query($sql,$dbh) or die(mysql_error());
> print("<body bgcolor=\"ff9900\"><p class=\"done\">You have successfully
> removed your items from the database.");
> ?>
Recomendation 2:
There is no need to use print("<html tags>") to draw the web page, you
can do it in this way:
<html>
<head> ... </head>
<body>
<form ...>
<table border=1>
<?
$result = mysql_query("SELECT ....",$db);
while ($myrow = mysql_fetch_array($result)){
?>
<tr>
<td><b>Type of car</b></td>
<td><?php print $myrow["car_type"] ?></td>
</tr>
<?
} // End of while
?>
</table>
</form>
<body>
</html>
> If anyone has the time to finish it or give me some pointers on what the
> hell I am doing wrong please let me know, I would be very glad to hear your
> opinion and the correct way to accomplish this. (And, yes I went through
> just about every tutorial I could find on how to delete records, which by
> the way did nothing for putting the results of a select statement into an
> array or variable for futher processing.) Have a good weekend everyone!!!
> Pissed and frustrated...
> Jas
<input type="text" name="carType" value="<? print $myrow["car_type"]
?>">
something like that?
-----=====(O)=====-----
Passing parameters to a PHP scripts: Do it through the URL
from a link:
<a href="script.php?id=20&action=Delete">Delete this car</a>
from javascript:
<script language="JavaScript">
window.location.href="script.php?id=20&action=Delete";
</script>
I hope that helps.
William.