Jump to content

Recommended Posts

Hello,

I am attempting a to code a simple php todo list but i'm having a problem deleting records. What happens is this: i link to this url: /delete.php?list_name=$list_name&table=lists and when I try the query below:

delete.php
[code]
<?
mysql_connect("localhost","xxxxxx","xxxxxx");
mysql_select_db("xxxxxxy") or die("Unable to select database.");

$table = $_GET["table"];
$list_name = $_GET["list_name"];


if($table == "lists")
{
    $query = "DELETE FROM lists WHERE name='$list_name'";
}
elseif($table == "items");
{
    $item_name = $_GET["item_name"];
    $query = "DELETE FROM items WHERE item_name='$item_name'";
}

mysql_query($query);
mysql_close;

if($table == 'lists')
{
    header("Location: index.php");
}
else
{
    header("Location: list.php?list_name=$list_name");
}

?>
[/code]

nothing happens, I'm not even returned any errors. Any suggestions?

EDITED
Link to comment
https://forums.phpfreaks.com/topic/10469-delete-mysql-records/
Share on other sites

[!--quoteo(post=377180:date=May 26 2006, 10:55 AM:name=sinisterguy)--][div class=\'quotetop\']QUOTE(sinisterguy @ May 26 2006, 10:55 AM) [snapback]377180[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hello,

I am attempting a to code a simple php todo list but i'm having a problem deleting records. What happens is this: i link to this url: /delete.php?list_name=$list_name&table=lists and when I try this query:

$query = "DELETE FROM lists WHERE name='$list_name'";

nothing happens, I'm not even returned any errors. Any suggestions?
[/quote]

well, basic that is exactly what gonna happen, cuz you did not query it, and all you did is set a variable $query to a string.

mysql_query($query);
or something like that.
Link to comment
https://forums.phpfreaks.com/topic/10469-delete-mysql-records/#findComment-39074
Share on other sites

[!--quoteo(post=377200:date=May 25 2006, 10:40 PM:name=hvle)--][div class=\'quotetop\']QUOTE(hvle @ May 25 2006, 10:40 PM) [snapback]377200[/snapback][/div][div class=\'quotemain\'][!--quotec--]
your query statement looks good,
I would echo the query to debug.
[/quote]

thanks for the tip, I fixed it by removing the elseif, it works if I just have the else, but if I test the second condition, it always returns true for some reason.
Link to comment
https://forums.phpfreaks.com/topic/10469-delete-mysql-records/#findComment-39167
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.