I'm trying to create a system that selects all the rows where username2 is equal to a variable, and don't understand why this wouldn't work. I'm fairly new to MySQL.
This does not work:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE username2
= " + $first_name;
Neither does this:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE
username2 = '" + $first_name + "'";
But this does:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE
username2 = 'JohnDoe'";
Thank you for taking the time to read this.
You can write it like this:
$sql = "SELECT username2, petbreed, petcost, pettype FROM pets WHERE username2 = '$first_name'"
.Use double quote around the whole expression and single quote around the variable.
+
is not concatenation sign in PHP. The dot.
is.