Jump to content

Warning: mysql_real_escape_string() expects at least 1 parameter


BradD

Recommended Posts

I'm a bit too green to figure this one out, been at it all day and still no further along...

Yes, I need to upgrade that book.

 

Anyway here's the error.

 

Warning: mysql_real_escape_string() expects at least 1 parameter, 0 given in /home/mnet/public_html/db_insert.php on line 18

There has been a system problem. Failed to add record to database.

 

Here's the code: "Please Help"

 

require_once('connectDB.php');

$password = md5($_POST['password']); // hash the password before the array_map()

array_map(mysql_real_escape_string(), $_POST ); // Since only one element won't need to be sanitized, run the entire $_POST array through mysql_real_escape_string.

$conf_code = md5(uniqid(rand(), true)); // generates confirmation code to use wth the confirmation email that gets sent //

$query = "INSERT INTO `members` (
`firstname`, `lastname`, `username`, `password`, `acccounttype`, `country`, `state`, `city`, `phone`, `mobile`, `business`, `email`, `website`, `signupdate`, `emailactivated`, `confirmed`
) VALUES (
'" . $_POST['firstname'] . "', '" . $_POST['lastname'] . "', '" . $_POST['username'] . "', '" . $password . "', '" . $_POST['accounttype'] . "', '" . $_POST['country'] . "', '" . $_POST['state'] . "', '" . $_POST['city'] . "', '" . $_POST['phone'] . "', '" . $_POST['mobile'] . "', '" . $_POST['business'] . "', '" . $_POST['email'] . "',  '" . $_POST['website'] . "', now(), '" . $conf_code . "', 0
)";
mysql_query($query) or die("There has been a system problem. Failed to add record to database.");

if( mysql_affected_rows($query) == 1 ) {
$id = mysql_insert_id();
$new_record = "SELECT `firstname`, `username`, `email`, `emailactivated` FROM `members` WHERE `id` = $id";
$result = mysql_query($new_record);
$array = mysql_fetch_assoc($result);

$email = $array['email'];
$subject = "Your confirmation code from the website";
$message = "Dear " . $array['firstname'] . ",\r\n";
$message .= "Thank you for registering at my website. To confirm your registration, please visit the link provided and enter the following confirmation code,\r\n";
$message .= $array['emailactivated'];
$from = "From: [email protected]\n";

if( mail($email, $subject, $message, $from) ) {
header('Location: success.php'); // redirects to a "landing page" if mail was sent successfully.
exit(); // stops further script execution after redirect.
}
}

array_map('mysql_real_escape_string', $_POST);

Thanks Alex: That got it, DUH!

 

Now I have another >              There has been a system problem. Failed to add record to database.

 

mysql_query($query) or die("There has been a system problem. Failed to add record to database.");

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.