<?php
$dbh=mysql_connect ("localhost", "******", "******") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("news_cms");
$id = $_POST['delete'];
if (isset ($_POST['deleted'])) {
echo $id;
$query = "DELETE FROM newscms WHERE `news_id` = {$id}";
if ($r = mysql_query($query)) {
echo 'The Post Has Been Deleted Successfully';
}
else { die('Couldnt Update Data Becase ' . mysql_error() . ''); }
}
?>
and it doesnt delete anything can anyone help me?
PHP wont run SQL query
Started by Hit3k, Mar 21 2006 08:49 PM
1 reply to this topic
#1
Posted 21 March 2006 - 08:49 PM
Ok.. In the CMS I'm coding the SQL query wont delete anything the code is
#2
Posted 21 March 2006 - 10:24 PM
Well, you got step one down by echoing the id... is that actually displaying a valid id that is in your database under the news_id column (or since it's in an if-statement, anything at all)?
If so, try using the following for your query:

And, just for future reference:
If so, try using the following for your query:
mysql_query("DELETE FROM newscms WHERE `news_id` = ".$id) or die('Couldn\'t Update Data Because ' . mysql_error());
echo 'The Post Has Been Deleted Successfully';
Keep in mind, what i did with the $id variable really isn't anything, just a matter of preference. I also fixed "Becase" And, just for future reference:
if ($r = mysql_query($query)) {
INSERT, DELETE, and maybe one or two other statements don't need to equal anything. Assigning them to a variable is just a waste if you're using the if-statement like that, or the "or die()" method.
Edited by rc69, 21 March 2006 - 10:24 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
