I am creating a registration page, and before the data is inserted into my database I need to check to see whether it already exists, but the SQL request I'm generating is missing a ' at the end.
SELECT * from users where firstname = 'Bob' and lastname = 'Smith' and
username = 'bobsmith' and email = 'bob@test.co.uk' and password = 'testing1
There is no ' showing after the password.
This is my PHP code:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$query1 = "SELECT * from users where firstname = '" .
$firstname .
"' and lastname = '" .
$lastname .
"' and username = '" .
$username .
"' and email = '" .
$email .
"' and password = '" . $password;
echo "<BR>Running query ... <BR>" . $query1;
$result1 = mysqli_query($cxn,$query1);
$numrows1 = mysqli_affected_rows($cxn);
I have tried adding a quote to the end of password like . $password . '";
however this is greying out the rest of the code below so it won't work. How can i fix this?
Update: I know this isn't the most secure way, but it is for a uni assignment and this is the way we are meant to do it.