开发者

Trying to delete mySQL record from HTML form... NOT WORKING

I have an html form with a select drop down list populated from mySQL, which correctly retrieves and displays the data in select drop down list.

BUT, I can't get the delete.php to work correctly. Here is the script for the select.php and delete.php.

<select name="name">
<?php
while ($line = mysql_fetch_array($result, MYSQL_BOTH)) {
?>
<option value="<?php echo $line['part_no'];?>"> <?php echo $line['part_no'];?> </option>
<?php
}
?>
</select>

delete.php

<?
$name = $_POST['name'];
$query = "delete from cartons_current where name = '".$name."'";
if(mysql_query($query)){
echo "deleted";}
else{
echo "fail";}
开发者_开发百科?>


Looking at the comments trailing above, it looks like the heckler's will just heckle. Some of us are still learning to program on stack, so I'm going to try to help.

Are you having column select issues - your while loop is not outputting values from the column you want the delete field match to go with?

Your sql query suggests you are polling a match against the name column, but your select dropdown seems about part_no.

Try: DELETE from cartons_current WHERE part_no=...

--

Also, as a first level prevention against SQL injection attacks, try sanitizing all your $_REQUEST field parameters (say, they're called $var) with

$var = mysql_real_escape_string($var)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜