ethan6 Posted February 28, 2010 Share Posted February 28, 2010 When I try to run this code: <? session_start(); $username = "user"; $password = "pass"; $hostname = "localhost"; $database = "database"; $con = mysql_connect($hostname, $username, $password) or die("Unable to connect to database."); mysql_select_db($database, $con) or die("Could not select itroni5_cart"); $answer_a = mysql_real_escape_string($_POST['wysiwyg'],$con); $answer = nl2br($answer_a); $query="INSERT INTO answers (idquestion, username, answer) VALUES ('".$_POST['idquestion']."','".$_SESSION['username']."', '".$answer."')"; $result=mysql_query($query) or die(mysql_error()); header("Location: answers.php"); ?> I get this error: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'user'@'localhost' (using password: NO) in /home/itroni5/public_html/testwysiwyg.php on line 4 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/itroni5/public_html/testwysiwyg.php on line 4 any ideas? Thanks! Link to comment https://forums.phpfreaks.com/topic/193623-mysql_real_escape_string-giving-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2010 Share Posted February 28, 2010 We would need to see the actual code in testwysiwyg.php that is producing the error on line 4. That's not it. Link to comment https://forums.phpfreaks.com/topic/193623-mysql_real_escape_string-giving-error/#findComment-1019228 Share on other sites More sharing options...
ethan6 Posted February 28, 2010 Author Share Posted February 28, 2010 sorry i figured it out--- my testwysiwyg.php file didn't have a connection to the database. just needed to connect and i was good! Link to comment https://forums.phpfreaks.com/topic/193623-mysql_real_escape_string-giving-error/#findComment-1019233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.