neex1233 Posted June 5, 2009 Share Posted June 5, 2009 <?php $allow = array ('2');include ("/home/Username/public_html/folder/protect.php"); ?> <title>Delete User</title> <?php $con = mysql_connect("localhost","My_Username","Password"); mysql_real_escape_string(mysql_select_db("My_DB", $con)); $username = $_POST['username']; if (isset($_POST['delete'])) { $sql = mysql_real_escape_string(mysql_query("DELETE FROM users WHERE username = '$username'")); mysql_query($sql) or die (mysql_error()); } ?> <strong>User Deleted</strong> <meta http-equiv="REFRESH" content="2;url=myurl"> That's my whole page. As you can see, there is no '1' on the page. Here is my 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 '1' at line 1 What is wrong with this script? It really does delete the user, but I always get this error and it doesn't redirect the user to my specified page. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/ Share on other sites More sharing options...
taquitosensei Posted June 5, 2009 Share Posted June 5, 2009 what's the first line from protect.php? Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850173 Share on other sites More sharing options...
PFMaBiSmAd Posted June 5, 2009 Share Posted June 5, 2009 What are all the lines in protect.php? Especially any query statements. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850174 Share on other sites More sharing options...
neex1233 Posted June 5, 2009 Author Share Posted June 5, 2009 I don't think it's them, because when I take the protect code off, it still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850184 Share on other sites More sharing options...
PFMaBiSmAd Posted June 5, 2009 Share Posted June 5, 2009 Upon closer review, you are escaping the whole result of one query and putting that into another one - $sql = mysql_real_escape_string(mysql_query("DELETE FROM users WHERE username = '$username'")); You are supposed to only escape string data that goes into the query and $sql should be just the query string because you are then putting that into another mysql_query() statement. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850190 Share on other sites More sharing options...
neex1233 Posted June 5, 2009 Author Share Posted June 5, 2009 So where do I put the escape string? Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850200 Share on other sites More sharing options...
Maq Posted June 5, 2009 Share Posted June 5, 2009 He told you, put it around the string then call the mysql_query() function. If you read the documentation you will see that mysql_real_escape_string takes a string and returns a string. It wouldn't make any sense to put it around the mysql_query when that returns a resource. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850234 Share on other sites More sharing options...
neex1233 Posted June 5, 2009 Author Share Posted June 5, 2009 I did that, but I'm still getting the same error. I might not have did it right, here's my new code: <?php $allow = array ('5');include ("/home/username/public_html/folder/protect.php"); ?> <title>Delete User</title> <?php $con = mysql_connect("localhost","Username","Password"); mysql_select_db("DB_Name", $con); $username = $_POST['username']; if (isset($_POST['delete'])) { $sql = mysql_query("DELETE FROM users WHERE username = '$username'"); mysql_query(mysql_real_escape_string($sql)) or die (mysql_error()); } ?> <strong>User Deleted</strong> <meta http-equiv="REFRESH" content="1;url=myurl"> Oh yes, and the script still works, it's just the error that shows up and none of the things I put in the body. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850275 Share on other sites More sharing options...
Maq Posted June 5, 2009 Share Posted June 5, 2009 Remove this line: $sql = mysql_query("DELETE FROM users WHERE username = '$username'"); Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850279 Share on other sites More sharing options...
neex1233 Posted June 5, 2009 Author Share Posted June 5, 2009 Actually, I fixed it. Well, not really, I just removed the 'mysql_error()' line. Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850280 Share on other sites More sharing options...
taquitosensei Posted June 5, 2009 Share Posted June 5, 2009 that didn't fix anything. You're just don't have any output when there's an error now. $sql = mysql_query("DELETE FROM users WHERE username = '".mysql_real_escape_string($username)."'"); Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850298 Share on other sites More sharing options...
Maq Posted June 6, 2009 Share Posted June 6, 2009 Actually, I fixed it. Well, not really, I just removed the 'mysql_error()' line. If you want to properly fix it, implement my suggestion and post the current code. (You can mark the top "Not Solved" again, by clicking the same button as marking it solved.) Quote Link to comment https://forums.phpfreaks.com/topic/161108-solved-strange-mysqlphp-script-error/#findComment-850615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.