Note that there are some explanatory texts on larger screens.

plurals
  1. POInput in database failure
    primarykey
    data
    text
    <p>I'm having trouble with the following code:</p> <pre><code>$sql= "INSERT INTO Users(Username, Password, Lastname, Email) VALUES ('$hash', '$lastname', '$email', '$email')"; mysqli_query($MyConnection, $sql); if(!mysqli_query($MyConnection, $sql)) { echo 'We are sorry, there are some problems with saving your data. Please try again within a few minutes.'; } else { echo 'We have succesfully saved your data. An activation e-mail will now be send to the e-mail address that you have provided us.'; } </code></pre> <p>I get no direct errors as due to mistyping or misusing a function. I do get however the message of the if-statement in a failure, the "We are sorry(..)" text.</p> <p>There must be a problem with the execution of the mysqli_query($MyConnection, $sql) function. But I don't see where it is.</p> <p>P.S. I can't post images, because my reputation is below 10. (Which is quite weird to limit it to that point)</p> <p>As some of you have provided most / all of the code:</p> <pre><code>&lt;?php // Opens the connection of the MySQL Database $MyConnection = mysqli_connect('fdb6.biz.nf', '1446018_amp', '-') or die("Could not connect to the database, please try again"); mysqli_select_db($MyConnection,'Users'); mysqli_connect_errno(); // Website Url: $website = 'http://www.askmephilosophy.co.nf/'; // Information provided by the user $username = $_POST['username']; $password = $_POST['password']; // Will get encrypted. $lastname = $_POST['lastname']; $email = $_POST['email']; // A higher "cost" is more secure but consumes more processing power $cost = 5; // Create a random salt $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.'); // Prefix information about the hash so PHP knows how to verify it later. // "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter. $salt = sprintf("$2a$%02d$", $cost) . $salt; // Hash the password with the salt $hash = crypt($password, $salt); $sql= "INSERT INTO Users(Username, Password, Lastname, Email) VALUES ('$hash', '$lastname', '$email', '$email')"; mysqli_query($MyConnection, $sql); var_dump(mysqli_error($MyConnection)); if(mysqli_query($MyConnection, $sql)) { echo 'We have succesfully saved your data. An activation e-mail will now be send to the e-mail address that you have provided us.'; } else { echo 'We are sorry, there are some problems with saving your data. Please try again within a few minutes.'; mysqli_error($MyConnection); } mysqli_close($MyConnection); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload