mark103 Posted October 2, 2010 Share Posted October 2, 2010 Hi guys, I am having a problem of deleting the rows in the database. I just receive two warnings of mysql_real_escape_string which they are: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'myusername'@'localhost' (using password: NO) in /home/username/public_html/mysite.com/delete.php on line 11 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/username/public_html/mysite.com/delete.php on line 11 failed The error are jumping on this line: return mysql_real_escape_string($value); Here it the full code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'username'); define('DB_PASSWORD', 'password'); define('DB_DATABASE', 'databasename'); function clean($value) { return mysql_real_escape_string($value); } $id = clean($_GET['id']); if ($id != NULL) { $query = @mysql_db_query(_DB,"DELETE FROM table1 WHERE $id = 'id"); $deleted = @mysql_affected_rows(); if($deleted > 0) { echo("worked"); } else { echo("failed"); } }else{ echo("failed"); } @mysql_close($link); ?> I have input the correct password, so what's wrong?? Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/ Share on other sites More sharing options...
herghost Posted October 2, 2010 Share Posted October 2, 2010 You have defined your database connection info, but have not actually connected to your database! Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118321 Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2010 Share Posted October 2, 2010 if you would remove all the @'s you put in your code to hide the php errors that are occurring on each one of those mysql_ instructions, you would probably learn that you are not making a connection to the database server. Also, mysql_db_query() is depreciated and should be replaced with a call to mysql_select_db() and you should use mysql_query() to perform queries. Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118322 Share on other sites More sharing options...
mark103 Posted October 2, 2010 Author Share Posted October 2, 2010 Thanks for your help, I have make some change: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'username'); define('DB_PASSWORD', 'password'); define('DB_DATABASE', 'databasename'); function clean($value) { return mysql_real_escape_string($value); } $id = clean($_GET['id']); if ($id != NULL) { $query = mysql_select_db("DELETE FROM table1 WHERE id = '$id'"); $deleted = @mysql_affected_rows(); if($deleted > 0) { echo("worked"); } else { echo("failed"); } }else{ echo("failed"); } @mysql_close($link); ?> However, I still getting the same errors. Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118343 Share on other sites More sharing options...
kenrbnsn Posted October 2, 2010 Share Posted October 2, 2010 You have defined your database connection info, but have not actually connected to your database! You still haven't connected to the database. Ken Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118345 Share on other sites More sharing options...
mark103 Posted October 2, 2010 Author Share Posted October 2, 2010 You have defined your database connection info, but have not actually connected to your database! You still haven't connected to the database. Ken I know that I still haven't connected to the database. In which line I need to change it with? Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118346 Share on other sites More sharing options...
jcbones Posted October 2, 2010 Share Posted October 2, 2010 Database connect Select a database Query a database Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118437 Share on other sites More sharing options...
mark103 Posted October 3, 2010 Author Share Posted October 3, 2010 Thanks, I have fixed the problem. However, I am getting an parse error with unexpected T_VARIABLE in /home/username/public_html/mysite.com/delete.php on line 19 Here it the line 19: $deleted = mysql_affected_rows(); Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118452 Share on other sites More sharing options...
jcbones Posted October 4, 2010 Share Posted October 4, 2010 Anytime you have an un-expected anything, always look at the line above that. You probably missed a semi-colon. Quote Link to comment https://forums.phpfreaks.com/topic/214985-receive-an-warning-of-mysql_real_escape_string/#findComment-1118768 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.