/    Sign up×
Community /Pin to ProfileBookmark

Grief with mysql_real_escape_string()

Hey guys,
Going completely out of my mind. Still quite new to this(learning from peachpit press books) got to a point, I thought I was understanding. Beginning to learn to use the msql_real_escape_string() but after defining my function I get an error message telling me im calling an undefined function the script is below. If anyone can help Id be much appreciated.

Here is the error message I get:
Fatal error: Call to undefined function: mysql_real_escape_string() in c:phpdev5wwwpublicveezkaffregister.php on line 15

Here is the script:
——————————————

<?php
$page_title = ‘Register’;
include (‘header.inc’);

if (isset($_POST[‘submit’])) { //handle the form

require_once (‘mysql_connect.php’); //open the database

//create escape_data function
function escape_data ($data) {
global $dbc;
if (ini_get(‘magic_quotes_gpc’)) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
}
//end of function

$message = NULL; //creating an empty variable

//check for a first name
if (empty($_POST[‘first_name’])) {
$fn = FALSE;
$message .= ‘<p>You did not enter your First Name!</p>.’;
} else {
$fn = escape_data($_
POST[‘first_name’]);

}

//check for a last name
if (empty($_POST[‘last_name’])) {
$ln = FALSE;
$message .= ‘<p>You did not enter your Last Name!</p>.’;
} else {
$ln = escape_data($_
POST[‘last_name’]);

}

//check for an email address
if (empty($_POST[’email’])) {
$email = FALSE;
$message .= ‘<p>You did not enter your email address.</p>’;
} else {
$e = escape_data($_
POST[’email’]);

}

//check for a username
if (empty($_POST[‘username’])) {
$u = FALSE;
$message .= ‘<p>You did not enter a Username.</p>’;
} else {
$u = escape_data($_
POST[‘username’]);

}

//check for a password and match against the confirmed password
if (empty($_POST[‘password1’])) {
$p = FALSE;
$message .= ‘<p>You did not enter a password</p>.’;
} else {
if ($_
POST[‘password1’] == $_POST[‘password2’]) {
$p = escape_data($_
POST[‘password1’]);
} else {
$p = FALSE;
$message .= ‘<p>Your password did not match the confirmed password.</p>’;
}
}

if ($fn && $ln && $e && $u && $p) { //if everything is ok then…

//make the query
$query = “INSERT INTO users (username, first_name, last_name, email, password, registration_date)
VALUES (‘$u’, ‘$fn’, ‘$ln’, ‘$e’, PASSWORD(‘$p’), NOW() )”;
$result = @mysql_query ($query);// Run the query

if ($result) {
echo ‘<p><b>You have been registered!</b></p>’;
include (‘footer.inc’);//include footer
exit();///ext script

} else { //if registration did not work
$message .= ‘<p>Registration incomplete. This could be due to a system error. We apologise for any inconvenience.</p>’ . mysql_error() . ‘</p>’;
}
mysql_close(); //close the databse connection
} else {
$message .= ‘<p>Please try again</p>’;
}
}//end of main conditional

// print any error messages
if (isset($message)) {
echo ‘<font color=”red”>’, $message, ‘</font>’;
}
?>

theres a form here blah blah blah—
————



———

<?php
include (‘footer.inc’);
?>


—————————————–

any help
Thanks

Bryndog ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 27.2005 — Well, let's start simple: Are you using PHP version 4.3.0 or later? (The function is not available before that.)

Assuming the version is OK, try echoing the value of $dbc and make sure it's getting set. If that's the problem, we'll need to see the include file that you require_once() to see what's going on. (The function only works if there's a valid mysql connection.)
×

Success!

Help @bryndog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...