Note that there are some explanatory texts on larger screens.

plurals
  1. POPDO Inserting and Execution
    text
    copied!<p>To preface things, I have very limited mysql knowledge and I decided to try and use PDO because I heard it is safer to use. That being said, if you see any injection liabilities as you attempt to help me out, let me know please! Anyways, I am having issues on how to handle the output of PDO queries, and just execution in general...</p> <p>The first thing I try to do is get the form data, and search the database to see if there are any other people with the same username or the same email:</p> <pre><code>if(isset($_POST['name']) &amp;&amp; !empty($_POST['name']) AND isset($_POST['password']) &amp;&amp; !empty($_POST['password']) AND $_POST['password'] == $_POST['password2'] AND isset($_POST['email']) &amp;&amp; !empty($_POST['email']) AND isset($_POST['year']) &amp;&amp; !empty($_POST['year']) AND isset($_POST['termsandconditions']) &amp;&amp; !empty($_POST['termsandconditions'])){ $name = $_POST['name']; $password = $_POST['password']; $email = $_POST['email']; foreach ($_POST['year'] as $year); $termsandconditions = $_POST['termsandconditions']; $idqry = $sql-&gt;prepare("SELECT id FROM users WHERE username = :idcheck"); $idqry-&gt;bindParam(':idcheck', $name, PDO::PARAM_STR,20); $idqry-&gt;execute(); $emailqry = $sql-&gt;prepare("SELECT id FROM users WHERE email = :idcheck"); $emailqry-&gt;bindParam(':emailcheck', $email, PDO::PARAM_STR, 40); $emailqry-&gt;execute(); </code></pre> <p>Later on, I try to take the PDO queries checking for a duplicate username/email and create different conditions:</p> <pre><code>if(!eregi("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(edu)$", $email)){ // Return Error - Invalid Email $msg = 'The email you have entered is invalid, please try again.&lt;br /&gt;*NOTE: You must use a .edu email to be able to register!'; }elseif($idqry != FALSE){ $msg = "That username has already been used, please try another one."; }elseif($emailqry != FALSE){ $msg = 'That email has already been used, &lt;a class=statusmsg href="../recovery/"&gt;need to recover your password?&lt;/a&gt;.'; }else{ $msg = 'Your account has been made, &lt;br /&gt; please verify it by clicking the activation link that has been sent to your email.'; $hash = md5(rand(0,1000)); $hashedpass = password_hash($password, PASSWORD_BCRYPT); $sqlinsert = $sql-&gt;prepare("INSERT INTO users (username, password, email, hash, year, termsandconditions) VALUES (:username, :password, :email, :hash, :year, :termsandconditions)"); $sqlinsert-&gt;execute(array( ':username' =&gt; $name, ':password' =&gt; $hashedpass, ':email' =&gt; $email, ':hash' =&gt; $hash, ':year' =&gt; $year, ':termsandconditions' =&gt; $termsandconditions)); } } </code></pre> <p>When I try to test this, I always get a $msg output of "That username has already been used, please try another one." (even if I enter a unique username)</p> <p>Do you see anything wrong? Also, is it possible to bindParam database INSERTs? Thanks!</p>
 

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