php - Registration process NOT inserting into database -
php - Registration process NOT inserting into database -
my register.inc.php
not inserting user info database. redirects me register_success.php
.
have missed in adding inserted data?
register.inc.php:
include_once 'config.php'; include_once 'db_connect.php'; $error_msg = ""; if (isset($_post['username'], $_post['firstname'], $_post['lastname'], $_post['home_address1'], $_post['home_address2'], $_post['home_city'], $_post['home_state'], $_post['home_zipcode'], $_post['email'], $_post['p'])) { // sanitize , validate info passed in $username = filter_input(input_post, 'username', filter_sanitize_string); $firstname = filter_input(input_post, 'firstname', filter_sanitize_strings); $lastname = filter_input(input_post, 'lastname', filter_sanitize_strings); $home_address1 = filter_input(input_post, 'home_address1', filter_sanitize_strings); $home_address2 = filter_input(input_post, 'home_address2', filter_sanitize_strings); $home_city = filter_input(input_post, 'home_city', filter_sanitize_strings); $home_state = filter_input(input_post, 'home_state', filter_sanitize_strings); $home_zipcode = filter_input(input_post, 'home_zipcode', filter_sanitize_strings); $email = filter_input(input_post, 'email', filter_sanitize_email); $email = filter_var($email, filter_validate_email); if (!filter_var($email, filter_validate_email)) { // not valid email $error_msg .= '<p class="error">the email address entered not valid</p>'; } $password = filter_input(input_post, 'p', filter_sanitize_string); if (strlen($password) != 128) { // hashed pwd should 128 characters long. // if it's not, odd has happened $error_msg .= '<p class="error">invalid password configuration.</p>'; } // username validity , password validity have been checked client side. // should should adequate nobody gains advantage // breaking these rules. // $prep_stmt = "select user_id users email = ? limit 1"; $stmt = $mysqli->prepare($prep_stmt); // check existing email if ($stmt) { $stmt->bind_param('s', $email); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { // user email address exists $error_msg .= '<p class="error">a user email address exists.</p>'; $stmt->close(); } $stmt->close(); } else { $error_msg .= '<p class="error">database error line 39</p>'; $stmt->close(); } // check existing username $prep_stmt = "select user_id users username = ? limit 1"; $stmt = $mysqli->prepare($prep_stmt); if ($stmt) { $stmt->bind_param('s', $username); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { // user username exists $error_msg .= '<p class="error">a user username exists</p>'; $stmt->close(); } $stmt->close(); } else { $error_msg .= '<p class="error">database error line 55</p>'; $stmt->close(); } // todo: // we'll have business relationship situation user doesn't have // rights registration, checking type of user attempting // perform operation. if (empty($error_msg)) { // create random salt //$random_salt = hash('sha512', uniqid(openssl_random_pseudo_bytes(16), true)); // did not work $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true)); // create salted password $password = hash('sha512', $password . $random_salt); // insert new user database if ($insert_stmt = $mysqli->prepare("insert users (username, firstname, lastname, home_address1, home_address2, home_city, home_state, home_zipcode, email, password, salt) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $insert_stmt->bind_param('sssssssssss', $username, $firstname, $lastname, $home_address1, $home_address2, $home_city, $home_state, $home_zipcode, $email, $password, $random_salt); // execute prepared query. if (! $insert_stmt->execute()) { header('location: ./error.php?err=registration failure: insert'); } } header('location: ./register_success.php'); } }
you utilize there undefined constant 3rd param of filter_input
function, filter_sanitize_strings
.
correct 1 without "s" @ end, filter_sanitize_string
.
$home_zipcode = filter_input(input_post, 'home_zipcode', filter_sanitize_string); // ^ etc.
php mysql
Comments
Post a Comment