Jump to content


Photo

PHP form not dropping data????


  • Please log in to reply
4 replies to this topic

#1 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 03 March 2006 - 08:42 PM

Hello, I am trying to delete data from an administration modual. [a href=\"http://www.uswebproducts.com/country_savings/admin/csmag_admin.php?c=view_vendors\" target=\"_blank\"]You can view it here[/a]
Below is the code I'm using. If someone can tell me where I went wrong, I would appreciate it.


<table width="100%" cellpadding="0" cellspacing="0" border="0">
<?php session_start();
include ('../connections/mysql_connect.php');//connect to database ?>
<tr>
<td width="25%" valign="top">
<table>
<tr>
<td class="content_blank"><strong>Current Vendors</strong></td>
</tr>
<tr>
<td><?php
$vendor_query = "SELECT vendor_name FROM vendors";
$result = mysql_query($vendor_query);
while (list($name) = mysql_fetch_row($result)) {
echo "<span class='content'>$name<br></span>";
}
?>
</td>
</tr>
</table>
</td>
<td width="75%" valign="top" class="form_left_side_border">
<table>
<tr>
<td class="content_blank"><strong>Remove a Vendor....</strong></td>
</tr>
<tr>
<td class="content_blank">
<?php
if(empty($_POST['submit'])) { //If the submit button has not been set we will echo a welcome statement
echo "<span class='content_blank'>Please select the name of the vendor to be removed.<BR></span>"; //end of the welcome message
}else{
if(!empty($_POST['vendor_id'])) {
$qry = mysql_query("DELETE * FROM vendors WHERE (vendor_id) = ('".$_POST['vendor_id']."');");
if($qry) { echo "<span class='content_blank'><strong>Vendor has been deleted</strong></span>"; }
else { echo "<span class='content_blank'><strong>Error deleting vendor</strong></span>"; }
} else {
echo "<span class='content_blank'><strong>Error: You must select the Vendor Name!</strong></span>";
}
}

echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td>
<br>
<form method='post' action='csmag_admin.php?c=view_vendors'>
<select name='cat_id'>
<option>- Please select one -</option>\n";
$qry = mysql_query("SELECT * FROM vendors;");
while($rows = mysql_fetch_assoc($qry)) {
echo "<option value='".$rows['vendor_id']."'>".$rows['vendor_name']."</option>\n";
}//#7
echo "</select>
<input name='vendor_id' type='submit' value='Remove'>
</form>
</td>
</tr>
</table>";
?>

</td>
</tr>
</table>
</td>
</tr>


</table>

#2 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 03 March 2006 - 09:05 PM

Your SQL syntax for DELETE is wrong, the correct syntax is:

DELETE FROM table WHERE column = 'value';


#3 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 03 March 2006 - 09:33 PM

[!--quoteo(post=351427:date=Mar 3 2006, 04:05 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Mar 3 2006, 04:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your SQL syntax for DELETE is wrong, the correct syntax is:

DELETE FROM table WHERE column = 'value';
[/quote]


OK I have updated to this and it still does not work. Any Thoughts??
$qry = mysql_query("DELETE FROM vendors WHERE (vendor_id) = ('".$_POST['vendor_id']."');");


#4 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 03 March 2006 - 09:43 PM

Should be that you are checking for 'submit' to be empty, while your submit button's name is 'vendor_id':

if(empty($_POST['submit'])) { //If the submit button has not been set we will echo a welcome statement

<input name='vendor_id' type='submit' value='Remove'>
So.. it is always trying to remove the vendor_id 'Remove'...
It should be trying to remove $_POST['cat_id']

#5 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 03 March 2006 - 11:16 PM

OK, I got it - again I can't thank you enough.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users