BradD Posted June 28, 2010 Share Posted June 28, 2010 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. } } Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/ Share on other sites More sharing options...
Mchl Posted June 28, 2010 Share Posted June 28, 2010 Perhaps look at the examples here: array_map Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/#findComment-1078140 Share on other sites More sharing options...
BradD Posted June 28, 2010 Author Share Posted June 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/#findComment-1078225 Share on other sites More sharing options...
Alex Posted June 28, 2010 Share Posted June 28, 2010 array_map('mysql_real_escape_string', $_POST); Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/#findComment-1078237 Share on other sites More sharing options...
BradD Posted June 28, 2010 Author Share Posted June 28, 2010 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."); Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/#findComment-1078280 Share on other sites More sharing options...
Mchl Posted June 28, 2010 Share Posted June 28, 2010 Try displaying mysql_error and $query to see how query was formed, and what error did MySQL issue Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/#findComment-1078281 Share on other sites More sharing options...
BradD Posted June 29, 2010 Author Share Posted June 29, 2010 Try displaying mysql_error and $query to see how query was formed, and what error did MySQL issue Thanks Mchl: That got it sorted, Quote Link to comment https://forums.phpfreaks.com/topic/206050-warning-mysql_real_escape_string-expects-at-least-1-parameter/#findComment-1078536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.