Link to home
Create AccountLog in
Avatar of Wanda Marston
Wanda MarstonFlag for Canada

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

Open in new window

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

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Wanda Marston

ASKER

<strong>Password:</strong><br>Must be between 6 and 20 characters long, with at least one lowercase letter, one uppercase letter, and one  number. For security purposes, do not use your password that you usually use with this email address. <input type="password" name="password1" size="20" value="
<?php if (isset($trimmed['password1'])) echo $trimmed['password1']; ?>"><br> <strong>Confirm Password:</strong><input type="password" name="password2" size="20" value=" <?php if (isset($trimmed['password2'])) echo $trimmed['password2']; ?>">

Open in new window


SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.

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



Thank you. I will investigate the above suggestions.