Jump to content


Photo

Delete MySQL records


  • Please log in to reply
6 replies to this topic

#1 sinisterguy

sinisterguy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 May 2006 - 12:55 AM

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
<?
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");
}

?>

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

EDITED

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 26 May 2006 - 01:49 AM

[!--quoteo(post=377180:date=May 26 2006, 10:55 AM:name=sinisterguy)--][div class=\'quotetop\']QUOTE(sinisterguy @ May 26 2006, 10:55 AM) View Post[/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.

Life's too short for arguing.

#3 sinisterguy

sinisterguy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 May 2006 - 01:57 AM

oops, I do have the mysql_query in there just forget to mension in in the post.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 May 2006 - 02:03 AM

Can you post the complete version of delete.php (at least from the start to the execution of the mysql query)? That'll make it easier to make suggestions.
Legend has it that reading the manual never killed anyone.
My site

#5 sinisterguy

sinisterguy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 May 2006 - 02:06 AM

there, i edited the original post

#6 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 26 May 2006 - 02:40 AM

your query statement looks good,
I would echo the query to debug.
Life's too short for arguing.

#7 sinisterguy

sinisterguy
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 May 2006 - 11:41 AM

[!--quoteo(post=377200:date=May 25 2006, 10:40 PM:name=hvle)--][div class=\'quotetop\']QUOTE(hvle @ May 25 2006, 10:40 PM) View Post[/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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users