4 Replies - 406 Views - Last Post: 22 July 2011 - 08:22 AM Rate Topic: -----

#1 TheMaster1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-October 10

php / mysql delete help

Posted 22 July 2011 - 08:08 AM

Im trying to delete a record from a table in the database and i want it to delete a record if to values are in the table



 mysql_query("DELETE FROM message WHERE user='$user' AND sender='$sender'"); 


I do this and it doesn't delete the data in the database

am i doing something wrong?

can you use this:
WHERE user='$user' AND sender='$sender' 

This post has been edited by TheMaster1: 22 July 2011 - 08:10 AM


Is This A Good Question/Topic? 0
  • +

Replies To: php / mysql delete help

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: php / mysql delete help

Posted 22 July 2011 - 08:11 AM

There is nothing wrong with your syntax as I can see. Put the sql in a variable so you can echo it out and see the query:
$sql = "DELETE FROM message WHERE user='$user' AND sender='$sender'"; 
if(!mysql_query($sql))
{
  echo "Problem with query $sql";
}




Then you can take the output and feed it directly to MySQL and see if any error message pop up.
Was This Post Helpful? 0
  • +
  • -

#3 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: php / mysql delete help

Posted 22 July 2011 - 08:11 AM

Well, I've never done a query like that. Try my way:

mysql_query("DELETE FROM `message` WHERE `user` = '" . $user . "' AND `sender` = '" . $sender . "'") or die(mysql_error());


What I did is basically the same thing I did. Try what Jstall said.

This post has been edited by EnvXOwner: 22 July 2011 - 08:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 TheMaster1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 07-October 10

Re: php / mysql delete help

Posted 22 July 2011 - 08:17 AM

thanks for the help guys but the problem was i declared the $user and $sender below the mysql_query delete in a while loop so it doesn't no what the $user and $sender is.

what a complete fail lol
Was This Post Helpful? 0
  • +
  • -

#5 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Re: php / mysql delete help

Posted 22 July 2011 - 08:22 AM

That's alright, everyone makes those mistakes every now and then.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1