Jump to content

TechnoDiver

Members
  • Posts

    173
  • Joined

  • Last visited

Community Answers

  1. TechnoDiver's post in Incorrect string type was marked as the answer   
    Hi, Phreaks, I'm stuck on something that maybe someone can help with
    on trying to send a user information to phpmyadmin I get this error ->
    There's 2 problems here, as you can see. 1) I've got an invalid datetime format. 2) is obviously the incorrect string value on my salt value.
    here is the corresponding code ->
    <?php if($validation->passed()) { $user = new User(); $salt = Hash::salt(32); try { $user->create(array( "username" => Input::get("usernane"), "password" => Hash::make(Input::get("password"), $salt), "email" => Input::get("email"), "salt" => $salt, "signup_date" => date_create('now')->format('Y-m-d H:i:s'), "role" => 2, )); $sent = true; } catch(Exception $e) { die($e->getMessage()); } } else { $errors = $validation->errors(); } It can be seen how I did both of them here. Additionally the Hash::salt method is here ->
    <?php public static function salt($length) { return random_bytes($length); } the column 'signup_date' is in my database as a datetime not null with 'none' as default.
    The column 'salt' is a VARCHAR(32) not null, 'none' as default
    Can anyone help me out with what I've done wrong, please. TIA
  2. TechnoDiver's post in Config.php was marked as the answer   
    I have the following code for a very simple registration form handler -
     
    //require('../../config/config.php'); require('reg_functions.php'); //assign clean form variables $firstname = clean_names($_POST['firstname']); $lastname = clean_names($_POST['lastname']); $username = clean_names($_POST['username']); $email = clean_email($_POST['email']); $email2 = clean_email($_POST['email2']); $password = clean_password($_POST['password']); $password2 = clean_password($_POST['password2']); $date = date("Y-m-d"); if(isset($_POST['register_button'])) { //validate & confirm emails match if($email == $email2) { if(filter_var($email, FILTER_VALIDATE_EMAIL)) { $email = filter_var($email, FILTER_VALIDATE_EMAIL); // I THINK I COULD DEF MAKE THIS EMAIL CHECK CLEANER - WORK ON THAT LATER //check if email exists in system already $email_check = mysqli_query($conn, "SELECT email FROM users WHERE email='$email'"); //number of rows returned with the email (this should be 0 to proceed) $number_rows = mysqli_num_rows($email_check); if($number_rows > 0) { echo "Email already in use <br>"; } else { echo "email is correct <br>"; } } else { echo "Invalid email format <br>"; } } else { echo "Emails don't match <br>"; } echo "First Name: " . $firstname . "<br>"; echo "Last Name: " . $lastname . "<br>"; echo "Username: " . $username . "<br>"; echo "Number of Rows: " . $number_rows . "<br>"; } the code that starts with the mysqli_query() function to check for matching emails is where it fails (white screen). I figured it may be because the $conn variable wasn't being associated with the $conn variable in the config.php file. So I added the require config.php at the top.
    Now it only works if both are commented out.  So in reality this could be 2 issues and I struggled with how not to ask too many questions in one post though they may be the same issue. I'm really new to php.
    Can someone explain the mechanics of whats going on (or not going on). to recap, this is the code that caused the white screen initially -
    // I THINK I COULD DEF MAKE THIS EMAIL CHECK CLEANER - WORK ON THAT LATER //check if email exists in system already $email_check = mysqli_query($conn, "SELECT email FROM users WHERE email='$email'"); //number of rows returned with the email (this should be 0 to proceed) $number_rows = mysqli_num_rows($email_check); if($number_rows > 0) { echo "Email already in use <br>"; } else { echo "email is correct <br>"; } and I realized it had no association to the $conn variable in the config.php file so I added the require config.php line at the top. This above code is obviously still not working and if I comment it out, the require config.php line still causes a white screen. This is my config file -
    ob_start(); session_start(); $timezone = date_default_timezone_set("America/xxxxxxxx"); $db_host = "localhost"; $db_user = "root"; $db_pass = ""; $db_name = "qcic"; $conn = mysqli_connect( $db_host, $db_user, $db_pass, $db_name ); if( $conn->connect_errno) { printf( "Connect Failed: %s\n", $conn->connect_error); exit(); } else { echo "Connected to database"; } ob_end_flush(); and I get the "Connected to database" echo so I have no idea what the problem is.
    Anyone with some time and more experience that can explain some of these things? thanks
×
×
  • 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.