Jump to content

Warning: mysql_real_escape_string() expects at least 1 parameter


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.
}
}

Perhaps look at the examples here: array_map

 

I have a basic, basic jist of arrays after writing several different types today to help myself gain more understanding of them, but I'm just not getting this.

 

Got any more clues?

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.");

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.