asked on
PHP Coding for a Registration page.
I have a registration page where the data is not going into the database and I am receiving two errors.
Following is my code:
$q = "SELECT id FROM users WHERE email=?";
$stmt = mysqli_prepare($db, $q) or trigger_error("Query: $q\n<br>MySQL Error: " . mysqli_error($db));
mysqli_stmt_bind_param($stmt, "s", $e);
mysqli_stmt_execute($stmt) or trigger_error("Query: $q\n<br>MySQL PS Error: " . mysqli_stmt_error($stmt));
$r = mysqli_stmt_get_result($stmt);
if (mysqli_num_rows($r) == 0) {
// Create the activation code:
$a = md5(uniqid(rand(), true));
// Add the user to the database:
// Make the query:
$q = "INSERT INTO users (tomorrowdate, first_name, mid_initial, last_name, username, email, pass, active, agree, date_expires) VALUES (?, ?, ?, ?, ?, ?, ?, '$a', 'Agree', DATE_ADD(NOW(), INTERVAL 2 YEAR) )";
// Prepare the statement:
$stmt = mysqli_prepare($db, $q);
// Bind the variables:
mysqli_stmt_bind_param($stmt, 'ssssssss', $tomorrowdate, $first_name, $mid_initial, $last_name, $username, $email, $pass, $a);
// Assign the values to variables:
$tomorrowdate = $_POST['tomorrowdate'];
$first_name = $_POST['first_name'];
$mid_initial = $_POST['mid_initial'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$a = md5(uniqid(rand(), true));
// Execute the query:
mysqli_stmt_execute($stmt);
Following are the two error messages;
An error occurred in script '/XXX.com/Register.php' on line 103: Undefined index: pass
Date/Time: 6-18-2023 20:35:10 - Line 103 - $pass = $_POST['pass'];
An error occurred in script 'xxxxxxxf.com/Register.php' on line 93: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement
Date/Time: 6-18-2023 20:35:10 - Line 93 - mysqli_stmt_bind_param($stmt, 'ssssssss', $tomorrowdate, $first_name, $mid_initial, $last_name, $username, $email, $pass, $a);
Hi,
If you are starting a new project I recommand the use of this script.
I'm using this small package from longtime and this is a very good base to learn this is well written and secure.
https://codecanyon.net/item/advanced-security-php-registerlogin-system/5282621
ASKER
Thank you. I will investigate the above suggestions.
ASKER
Open in new window