mysql DELETE not working

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

mysql DELETE not working

 
0
  #1
Oct 18th, 2006
Hey everyone, I'm using php to delete a row from a table in a database in mysql, but it's not working. I'm not even trying to do anything fancy, just delete one row. Here's the code:

[PHP]<?
include 'config.php';

$recordid = $_POST['recordid'];

echo $recordid;

mysql_query("DELETE FROM employees WHERE recordid='$recordid'")
or die('sorry, no query');


echo "You have successfully deleted the user."


?>[/PHP]

The database is connecting properly, I double checked that. The variable $recordid is echoing out properly, and I even tried not using the variable, and just placing the actual number of the record id in the code instead, but still didn't work. And yes, I did try copying and pasting that code directly in to the mysql command line. Works perfectly no errors. So how come the query never works? The query dies every time, no fail, but works every time when I use the exact same command in the mysql command line, straight copy and paste, no kidding.

Any ideas? I know it's going to be something stupid, and I'm going to kick myself when I find out, but it's killing me!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: mysql DELETE not working

 
0
  #2
Oct 18th, 2006
change your query to this:
[php]
mysql_query("DELETE FROM employees WHERE recordid='".$recordid."'")
[/php] you cant wrap a variable in single quotes as it will be trated as literal.
Last edited by sn4rf3r; Oct 18th, 2006 at 12:26 pm. Reason: spelling
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: mysql DELETE not working

 
0
  #3
Oct 18th, 2006
Check for errors with mysql_errorno or a similar function. That might help you out some.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql DELETE not working

 
0
  #4
Oct 19th, 2006
Originally Posted by sn4rf3r View Post
change your query to this:
[php]
mysql_query("DELETE FROM employees WHERE recordid='".$recordid."'")
[/php] you cant wrap a variable in single quotes as it will be trated as literal.
Thanks, but that doesn't seem to work either. Plus, I'm pretty sure I've done mysql_query's before with variables in single quotes and it works just fine. And besides, I'v even tried just putting the actual record id in that space, and it doesn't work. For instance, I put:
[PHP]mysql_query("DELETE FROM employees WHERE recordid='8'")[/PHP]
And it still doesn't work. I don't understand!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql DELETE not working

 
0
  #5
Oct 19th, 2006
Originally Posted by Puckdropper View Post
Check for errors with mysql_errorno or a similar function. That might help you out some.
How exactly do you use mysql_errorno? I can't find any documentation on it. I even looked on http://dev.mysql.com and couldn't find it. I did try mysql_error, and it spit this error out:
Access denied for user: 'user@10.0.0.1' to database 'mydatabase'
I changed the username, IP, and database name, just in case you're wondering. The problem is, I'm not having problems connecting to the database. the config.php file contains a mysql_error that should tell me if there were any connection problems. And the user that this error is telling me can't get access is the same user getting access in all my other scripts. And they're not having any problems. This is really buggin.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: mysql DELETE not working

 
0
  #6
Oct 19th, 2006
so be carefull while using keywords. it's dangerous.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql DELETE not working

 
0
  #7
Oct 19th, 2006
Originally Posted by vishesh View Post
so be carefull while using keywords. it's dangerous.
What?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 31
Reputation: DGStudios is an unknown quantity at this point 
Solved Threads: 3
DGStudios DGStudios is offline Offline
Light Poster

Re: mysql DELETE not working

 
0
  #8
Oct 19th, 2006
One thing you might try is to store you're query in a variable before putting it into the mysql_query() function.

$query = "DELETE FROM employees WHERE recordid='$recordid'";
$results = @mysql_query($query);


Mind You I used the storing of results. This is good practice as it allows for good error checking. I use it all the time, as queries ALWAYS return a value. while Selects and whatnot actually return values the others return a true/false value set.... or at least false when they fail.

Try it that way and see if that fixes it. If not.. take the query into a database interface and run the query. You might have to echo the query out to get the exact query, and just run it. That will give you a better understanding of exactly WHERE the issue is in the query.
http://img.photobucket.com/albums/v6.../dgstudios.jpg
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 133
Reputation: sn4rf3r is an unknown quantity at this point 
Solved Threads: 2
sn4rf3r's Avatar
sn4rf3r sn4rf3r is offline Offline
Junior Poster

Re: mysql DELETE not working

 
0
  #9
Oct 19th, 2006
just looks like he cant connect to the database from where he is.

  1. mysql> select * from mysql.user where user = 'username'
  2. \G;
  3. mysql> GRANT ALL PERMISSIONS ON *.* TO 'joe'@'10.0.1.1' IDENTIFIED BY 'password'
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: mysql DELETE not working

 
0
  #10
Oct 20th, 2006
Originally Posted by DGStudios View Post
One thing you might try is to store you're query in a variable before putting it into the mysql_query() function.

$query = "DELETE FROM employees WHERE recordid='$recordid'";
$results = @mysql_query($query);


Mind You I used the storing of results. This is good practice as it allows for good error checking. I use it all the time, as queries ALWAYS return a value. while Selects and whatnot actually return values the others return a true/false value set.... or at least false when they fail.

Try it that way and see if that fixes it. If not.. take the query into a database interface and run the query. You might have to echo the query out to get the exact query, and just run it. That will give you a better understanding of exactly WHERE the issue is in the query.
Thanks, I'll give that a try.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC