1

my code-

require 'database.php';

$title = mysql_real_escape_string($_POST['title']);  //line 48
$cat = $_POST['cat'];
$txtart = mysql_real_escape_string($_POST['artbody']); //line 50
$date = date("d-m-y");

$q = "INSERT INTO tblarticle (art_title, art_cat, art_des, art_date) VALUES ('$title', '$cat', '$txtart', '$date')";

ERROR-->
Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\shizin\admin\newArticle.php on line 48

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\shizin\admin\newArticle.php on line 48

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\shizin\admin\newArticle.php on line 50

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\shizin\admin\newArticle.php on line 50

But data is getting saved in DB but null titile and artbody fields

1
  • You will need to escape $_POST['cat'] as well. Commented Aug 19, 2010 at 9:01

3 Answers 3

6

mysql_real_escape_string tries to connect to the local database, so it can fetch the settings it needs to escape the string correctly for that system.

You can tell the function which connection to use by passing in a link identifier as a second argument:

mysql_real_escape_string($string, $link)

Sign up to request clarification or add additional context in comments.

Comments

3

Please check your MySQL username and password and make sure you're entering them properly in mysql_connect. According to the error you didn't run mysql_connect with a password, which may be causing these problems.

Comments

0

Check database.php connection strings, and the MySQL server is running as mysql_real_escape_string needs a valid open database connection to work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.