Jump to content

warning in mysql_real_escape_string

- - - - -

  • Please log in to reply
1 reply to this topic

#1
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts
Good day!

I am new in template in php like calling the .html webpage in php and I encountered warning in mysql_real_escape_string

here is my code:

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE);

include('includes/config.sender.php');

include('includes/template.inc');



session_start();


  if (isset($_SESSION['logged_in'])) {

     header('Location:machine1.php');

     die();

  }



 if (isset($_POST['submit'])) {

	$username=$_POST['username']; 

	$password=$_POST['password'];



	$username = mysql_real_escape_string($username);

	$password = mysql_real_escape_string(sha1($password));

	

	//$username = $_DB->getEscaped($username);

	//$password = $_DB->getEscaped(sha1($password));



	//mysql_query("UPDATE machine_problem_rhoda_user SET password = '$password' WHERE username = '$username'");

	

	$sql_update = "UPDATE machine_problem_rhoda_user SET 

					password = '$password', 

			   WHERE username = '$username'";

	

	$sql_select = "SELECT

					username,

					password

			   FROM

					machine_problem_rhoda_user

			   WHERE

			   		username='$username'

					AND

					password='$password'

					";

					

	$result = $_DB->opendb($sql_select);


	$result=mysql_query($sql_select);

	

	$count=mysql_num_rows($result);


	if($count==1){  

		$_SESSION['logged_in'] = true;

		header("location:machine1.php");

	}

	else {

	echo "<center>";

	echo "Wrong Username or Password";

	echo "</center>";

	}

}


$tpl = new Template('.', 'keep');

$tpl->set_file(array('handle' => 'html/index.html'));

$tpl->parse('handle', array('handle'));

$tpl->p('handle');

?>


And I got this warning:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /opt/zeva/releases/ZEVA.sandbox/machine_problem/rhoda/index.php on line 20

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /opt/zeva/releases/ZEVA.sandbox/machine_problem/rhoda/index.php on line 20

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /opt/zeva/releases/ZEVA.sandbox/machine_problem/rhoda/index.php on line 21

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /opt/zeva/releases/ZEVA.sandbox/machine_problem/rhoda/index.php on line 21

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
This is addressed in our FAQ (#9 Note 1) http://forum.codecal...-questions.html
The mysql_* functions can only be performed when there is an open link to a database with mysql_connect, you appear to be escaping prior to your opendb call.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users