简体   繁体   中英

mySql Delete only removes the data not the entire entry

Hi all I have this line in my php code

 `$insert = "DELETE FROM allocation_table WHERE job = '$jobnumber' " ;
  Mysql_query ($insert) ;`

The problem is it will remove all the values from the one line in my table but not the entry itself. as you can see in the picture if I delete where job = 315 , it does not delete the line but does delete all the entries

Yet in this code that preceeds it (a different table) . it works fine and the whole line is removed

$insert = "DELETE FROM event WHERE jobnumber = '$jobnumber' " ; 
mysql_query ($insert) ;enter code here

can anyone offer some advice please ?? alt text http://img34.imageshack.us/img34/4431/tablenj.jpg

Do you have any error handling routines in your code?
You might also want to add some debug output (or even better use a debugger like xdebug )
(oversimplified) example:

$insert = "DELETE FROM allocation_table WHERE job = '$jobnumber' " ;
echo '<pre>Debug: query=', htmlspecialchars($insert), '</pre>';
$rc = mysql_query($insert);
if ( !$rc ) {
  echo '<pre>mysql_query failed: ', mysql_error(), '</pre>';
}
else {
  echo '<pre>Debug: affected rows=', mysql_affected_rows(), '</pre>';
}

$insert = "DELETE FROM event WHERE jobnumber = '$jobnumber' " ; 
echo '<pre>Debug: query=', htmlspecialchars($insert), '</pre>';
$rc = mysql_query($insert);
if ( !$rc ) {
  echo '<pre>mysql_query failed: ', mysql_error(), '</pre>';
}
else {
  echo '<pre>Debug: affected rows=', mysql_affected_rows(), '</pre>';
}

Maybe you have some weird setting on your MySQL table that is causing the query to function differently. Did you create the table yourself (with PMA?) or import it from somewhere else?

When you delete using PHPMyAdmin, what is the query that it runs?

Try deleting in PhpMyAdmin and see what happens. At least there you'll be able to easily see any error message.

Do you have foreign keys defined and/or table constraints?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM