ERROR: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 7
Trying to use PDO to make this connection and form the query that checks for a username if it exists or not upon input into field after submit is pressed.
HTML:
<form action="inc/check_regUsr.php" method="post" id="userLogon">
<div class="field required">
Username: <input type="text" name="regduser" tabindex="1" /><br />
</div>
<div class="field required">
Password: <input type="password" name="regdpass" tabindex="2" /><br />
</div>
<input type="submit" name="submitUser" />
</form>
PHP
<?php
#Login Details
require_once('dbcred.php');
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
#Check for Existing User
$q = $conn->query("SELECT uname FROM Student WHERE $_POST['regduser'] = uname");
$stmt = $conn->prepare($q);
$r->execute($q);
if($q($r)>= 1){ #if there are 1 or more users with enter username, deny.
echo "Sorry, username already exists";
}
else{
echo "Success";
}
?>
Enclose your complex variables in
{}inside a double-quoted string:It looks like your SQL WHERE clause is backward though, and missing quotes. Should be
You have another problem, where you are first calling
$conn->query()and then attempting to create a prepared statement.The call to
query()is unnecessary and actually dangerous. Instead create a proper prepared statement with?placeholders: