Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've just now started with your tutorial,

I'm unable to debug this error code

Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\MyFirstWebSite\register.php:18 Stack trace: #0 {main} thrown in C:\xampp\htdocs\MyFirstWebSite\register.php on line 18

What I have tried:

<html>
<head>
	<title>My First PHP Website</title>
</head>
<body>
	<h2>Registration Page</h2>
	<a href="index.php">Click here to go back</a><br/>
		<form action="register.php" method="post">
			Enter Username: <input type="text" name="username" required="required"/><br/>
			Enter Password: <input type="password" name="password" required="required"/><br/>
			<input type="submit" value="Register"/>
		</form>
</body>
</html>

<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
	$username = mysql_real_escape_string($_POST['username']);
	$password = mysql_real_escape_string($_POST['password']);

	echo "Username entered is:". $username . "<br/>";
	echo "Password entered is:". $password;
}
?>
Posted
Updated 29-Dec-17 7:16am

1 solution

You might be using a recent PHP version; mysql_real_escape_string is removed in PHP 7.0.0. Quoting the documentation:


Warning

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi[^] or PDO_MySQL[^] extension should be used. See also MySQL: choosing an API[^] guide and related FAQ[^] for more information. Alternatives to this function include:

mysqli_real_escape_string()[^]
PDO::quote()[^]
 
Share this answer
 
v2
Comments
Member 13599481 29-Dec-17 16:40pm    
Can you help me with a example code using mysqli? I'm just a beginner and I don't know how to complete it???


<title>My First PHP Website


Registration Page


Click here to go back

Enter Username:
Enter Password:





<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$username = mysqli_real_escape_string($_POST['username']);
$password = mysqli_real_escape_string($_POST['password']);

echo "Username entered is:". $username . "";
echo "Password entered is:". $password;
}
?>
Thomas Daniels 30-Dec-17 1:40am    
I don't know a lot of PHP/MySQL from the top of my head; I'd have to read the docs before I could do that. So instead, I encourage you to read the documentation so you learn how to do it yourself.

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