Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to PHP and my sql. I created i register form for users to registee but i get this error
Fatal error:uncaught Error:Call to undefined mysql_real_escape_string()
. here is my code.
<?php
 session_start();
 
// connect to databse
$db = mysqli_connect("localhost", "dbnameuser","password","dbname");

if (isset($_POST['register_btn'])){
	session_start();
	$username = mysql_real_escape_string($_POST['username']);
	$email = mysql_real_escape_string($_POST['email']);
	$password = mysql_real_escape_string($_POST['password']);
	$password2 = mysql_real_escape_string($_POST['password2']);
	
	if ($password == $password2){
		//create user
		$password =md5($password);// hash password before storing for security purposes
		$sql = "INSERT INTO users(username,email,password) VALUES('$username','$email,'$password')";
		mysqli_query($db, $sql);
		$_SESSION['message'] = "You are now logged in";
		$_SESSION['username'] = $username;
		header("location: home.php"); //redirect to home page
		
	}else{
		$_SESSION['message'] = "The two passwords do not match";
	}
	}

?>


What I have tried:

I searched online and this site seems to have more info on the fix e.g
mysql_real_escape_string() extension 
is removed, i dont know what exact syntax to enter for the
MySQLi or PDO_MySQL extension
they sugggest to use .
Posted
Updated 7-Jun-20 22:40pm

i tried to change mysql_real_escape_string to MySQLi still got the error.
 
Share this answer
 
Comments
Richard MacCutchan 8-Jun-20 4:40am    
This is not a Solution. If you have additional comments then edit your question. However, see the link below.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900