mat3000000 Posted October 31, 2010 Share Posted October 31, 2010 No errors come up when I run this but it just doesn't delete the entry. <? $rec = $_POST['stock']; if (!$rec){ die ('Please eneter a stock number'); } $link = mysql_connect("xxxx","xxx","xxx"); mysql_select_db('wadkin', $link) or die( "Unable to select database"); mysql_query("DELETE FROM 'wadkin'.'stocklist' WHERE 'stocklist'.'Stock Number' = $rec") or die ('Query failed'); mysql_close($link); ?> Can someone please correct, (btw I have also tried... "DELETE FROM stocklist WHERE 'Stock Number' = $rec") Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/ Share on other sites More sharing options...
Pikachu2000 Posted October 31, 2010 Share Posted October 31, 2010 You're using quotes around the table and field names. It isn't really necessary in this case, but if you feel like enclosing them for a query in MySQL, use backticks instead. `table`. `field` Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1128733 Share on other sites More sharing options...
rwwd Posted October 31, 2010 Share Posted October 31, 2010 <?php error_reporting(E_ALL); $link = mysql_connect("xxxx","xxx","xxx"); mysql_select_db('wadkin', $link) or die( "Unable to select database"); //'Catch' the $_POST value being submitted if (isset($_POST['stock']) && !empty($_POST['stock'])){ $rec = strip_tags(mysql_real_escape_string($_POST['stock']));//sanitise first //issue the query $res = mysql_query("DELETE FROM `wadkin`.`stocklist` WHERE `stocklist`.`Stock Number` = ".$rec." ") or die ('Query failed'.mysql_error()); //Check that the query was successful if($res){ echo "record deleted!"; exit; } else{ echo "Uh-oh, something went wrong!"; exit; } } else{ echo "Please enter a valid stock number!"; exit; } ?> There are better ways, but this will work fine for what you are trying to achieve. If the 'stock' value isn't numerical, you will need to quote ('".$rec."') that value in the sql. Rw Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1128739 Share on other sites More sharing options...
mat3000000 Posted November 1, 2010 Author Share Posted November 1, 2010 I am now given an error: Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\admin\delete.php on line 10 ??????? Please can someone correct. Thanks Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129070 Share on other sites More sharing options...
mat3000000 Posted November 1, 2010 Author Share Posted November 1, 2010 I am now given an error: Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\admin\delete.php on line 10 Line 10 is: $res = mysql_query($link, "DELETE FROM 'stocklist' WHERE 'Stock Number'=".$rec."") ??????? Please can someone correct. Thanks Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129071 Share on other sites More sharing options...
Pikachu2000 Posted November 1, 2010 Share Posted November 1, 2010 You need to reverse the order of the parameters in mysql_query. The query string comes first, then if needed, the db connection. Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129075 Share on other sites More sharing options...
mat3000000 Posted November 1, 2010 Author Share Posted November 1, 2010 Now I have a new error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('stocklist' WHERE 'Stock Number'=S7466)' at line 1 HELP! :S Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129077 Share on other sites More sharing options...
mikosiko Posted November 1, 2010 Share Posted November 1, 2010 read answer #1 again... preferably twice Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129083 Share on other sites More sharing options...
mat3000000 Posted November 1, 2010 Author Share Posted November 1, 2010 Keep forgetting back-sticks not quotes! :S oops! You'll all be glad to know I got this... Unknown column 'S8637' in 'where clause' What does this mean in english please? If it means it can't find this entry in the table under `Stock Number` then something has gone wrong, I know that this number is in my table???? Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129088 Share on other sites More sharing options...
mikosiko Posted November 1, 2010 Share Posted November 1, 2010 :'( read last paragraph in answer #2.... maybe three times... :-\ Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129090 Share on other sites More sharing options...
mat3000000 Posted November 1, 2010 Author Share Posted November 1, 2010 Bloody quotes and lines! I get so confused... Thanks for all your help guys!! Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129095 Share on other sites More sharing options...
rwwd Posted November 1, 2010 Share Posted November 1, 2010 :'( read last paragraph in answer #2.... maybe three times... :-\ Lol! we all have days like that from time to time... Rw Link to comment https://forums.phpfreaks.com/topic/217384-delete-database-entry-code-help/#findComment-1129101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.