Jump to content

PHP form not dropping data????


sjones

Recommended Posts

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>
Link to comment
Share on other sites

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

[code]DELETE FROM table WHERE column = 'value';[/code]
[/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']."');");
Link to comment
Share on other sites

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

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

[code]<input name='vendor_id' type='submit' value='Remove'>[/code]
So.. it is [b]always[/b] trying to remove the vendor_id 'Remove'...
It should be trying to remove $_POST['cat_id']
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.