Jump to content

Recommended Posts

Hey all. I'm trying to delete a row from a table using a drop down menu. The code in the mysql must be wrong but i can't see where. Here's the code. Any Ideas?

 

 <?php


$con = mysql_connect("localhost","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("databasename", $con);

$sql="SELECT Name, Paid FROM Stag";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $Name=$row["Name"];
    $thing=$row["Paid"];
    $options.="<OPTION VALUE=\"$Name\">".$Name."</option>";
}
?>
<br>
<form action="http://xxxxxxx/delstag.php" method="post">
<SELECT NAME=thing>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT> 
<input type="submit" />
</form>     

$result = mysql_query("DELETE FROM Stag WHERE Name = $Name");

Link to comment
https://forums.phpfreaks.com/topic/199284-why-wont-the-row-delete/
Share on other sites

If you're passing the value from the form the next page via POST, the 'delstag.php' your code should look something like:

 

$Name = mysql_real_escape_string($_POST['thing']);
if (!$result = mysql_query("DELETE FROM Stag WHERE Name = '$Name'"))
{
   throw new Exception('Error: ' . mysql_error());
}
else
{
   echo $Name . " has been deleted.";
}

 

 

:facepalm:

 

He meant in the SQL.

 

And yes, I meant the SQL.  But your HTML should have quotes around attribute values as well.

 

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.