Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
we are getting this error during register.php
Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string()

What I have tried:

on registration php i m getting this error
Posted
Updated 23-Jun-22 20:20pm
Comments
Richard Deeming 31-Mar-17 14:51pm    
That means there's an error somewhere in your secret code.

But since you've declined to share any of the relevant code with us, we can't tell you where, or how to fix it.

All we can tell you is that you're trying to call a function called mysql_real_escape_string, and that function is not defined.
Bryian Tan 31-Mar-17 16:57pm    
Maybe that function is obsolete depending on the PHP version that the application is using. My gut feeling is, the application should use mysqli_real_escape_string(). We don't know until the day you decide to share your secret code ...

PHP: mysql_real_escape_string - Manual[^]

Read the mysql_real_escape_string()[^] documentation:
Quote:
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:
 
Share this answer
 
Comments
Member 13097810 4-Apr-17 10:02am    
SIR THANKS
pls find my code

<html>
	<head>
		<title>BHARAT HILLS</title>
	</head>
	<body>
		<h2>Registration Page</h2>
		<a href="index.php">Click here to go back</a><br/><br/>
		<form action="register.php" method="POST">
		Enter Username:  <input type="text" Name ="username" required ="required"/><br/><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']);
	$bool=true;
	
		mysql_connect("localhost", "root","") or die(mysql_error());//connect to server
		mysql_select_db("first_db") or die("cannot connect to database");//connect to database
		$query=mysql_query("select * from Users"); //query the user table
		while($row=mysql_fetch_array($query)) //display all rows from query
		{
				$table_users=$row['username']; //the first username row is passed on to $table_users,and so on untill the query is finish
				if($username==$table_user)// checks if there are any matching fields
				{
						$bool=false;//sets bool to false
						print'<script>alert("username has been taken!"):</script>';//redirects to register.php
						
				}
		}
		
		if($bool) //checks if bool is true
		{
				mysql_query("insert into user (username,password) values ('$username','$passwors')");//inset the vallue to table users
				print '<script>alert("Successfully Registered!");</script>';//prompts the user
				print '<script>window.location.assign("register.php");</script>';//redirect to register.php
				}
				
				}
?>
 
Share this answer
 
Comments
Member 13097810 1-Apr-17 9:17am    
sir in my code
mysql_connect("localhost", "root","") or die(mysql_error());//connect to server
localhost is underline red color means not connected kindly help i m just using ur code i m new for php
Richard Deeming 3-Apr-17 13:52pm    
If you want to update your question, click the green "Improve question" link at the bottom of your question.

DO NOT post your update as a "solution".

And DO NOT mark your "solution" as the accepted solution to your question!
<?php
	$username = "";
	$email = "";
	$errors = array();
		// connect to the database
	$db = mysqli_connect('localhost', 'root', '', 'registration');

	// if register button is clicked

	if(isset($_POST['register'])){
		$username = mysql_real_escape_string($_POST['username']);
		$email = mysql_real_escape_string($_POST['email']);
		$password_1 = mysql_real_escape_string($_POST['password_1']);
		$password_2 = mysql_real_escape_string($_POST['password_2']);

		//ensure that the form field are filled properly

		if (empty($username)) {
			array_push($errors, "Username is required"); 
		}
		if (empty($email)) {
			array_push($errors, "Email is required"); 
		}
		if (empty($password_1)) {
			array_push($errors, "Password is required"); 
		}
		if (empty($password_1 != $password_2)) {
			array_push($errors, "Two password do not match"); 
		}

		// if there are no errors, save user to the database
		if (count($errors) == 0) {
			$password = md5($password_1); //encrypt password before storing in database (security)
			$sql = "INSERT INTO users (username, email, password) 
						VALUES ('$username','$email', '$password')";
			mysqli_query($db,$sql);
		}

	}
?> 
 
Share this answer
 
Comments
Richard Deeming 11-Sep-18 12:15pm    
The question has already been solved.

And the md5 function[^] specifically warns that it is not suitable for securing passwords. You should be using password_hash[^] and password_verify[^] instead.

PHP: Password hashing FAQ[^]

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