| | |
mysql DELETE not working
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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!
[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!
•
•
Join Date: Jul 2004
Posts: 494
Reputation:
Solved Threads: 21
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.
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.
•
•
•
•
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.
[PHP]mysql_query("DELETE FROM employees WHERE recordid='8'")[/PHP]
And it still doesn't work. I don't understand!
•
•
•
•
Check for errors with mysql_errorno or a similar function. That might help you out some.
•
•
•
•
Access denied for user: 'user@10.0.0.1' to database 'mydatabase'
•
•
Join Date: Mar 2006
Posts: 31
Reputation:
Solved Threads: 3
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.
$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
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
just looks like he cant connect to the database from where he is.
PHP Syntax (Toggle Plain Text)
mysql> select * from mysql.user where user = 'username' \G; mysql> GRANT ALL PERMISSIONS ON *.* TO 'joe'@'10.0.1.1' IDENTIFIED BY 'password'
•
•
•
•
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.
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: help
- Next Thread: Need more help with "if"
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube







What?