Unkown COlumn

Not sure if this is a PHP or MySQL error…

Here is the error I am getting:
Unknown column ‘Johny’ in ‘field list’

Here is the code:



$reg = "INSERT INTO users SET username = " . $username . ", password =" .  $pass . ";";
mysqli_query($link, $reg) or die ('Error Creating Username: ' . mysqli_error($link) . '...Please Retry');


verified values in the variables
$username = Johny
$password = John

Any ideas as to why this error is coming up

Yeah., Use or left them blank. But the rule is., You should not use single quotes ’ ’ to enclose the column name or table name in the query.

This is not necessary to use with the table column name.

This should be left blank also like this

$reg="insert into users (username,password) values ('".$username."','".$password."')";

Single quotes are not allowed with the column name as given by RNEL

try.,

$reg=“insert into users (username,password`) values (‘$username’,‘$password’)”;

Sorry for the confusion…
Here’s the string I was using


$reg = "INSERT INTO users SET username = " . $username . ", password =" .  $pass . ";"; 

and this was the result…

INSERT INTO users SET username = username , password = pass;

Here’s the fix…


$reg = "INSERT INTO users SET username = '" . $username . "', password ='" .  $pass . "';";

I placed single quotes around $username and $password in the search string so it came up like this.

INSERT INTO users SET username = ‘username’ , password = ‘pass’;

@RNEL

I definitely do that (been burned before :blush:), I didn’t post that part because I wanted to make it as simple as possible.

Figured it out… I forgot the quotes around the variables $username and $password


$reg="insert into users ('username','password') values ('" . $username . "','" . $password . "')";

filter user inputs and don’t forget to escape string :slight_smile:

$reg=“insert into users (username,password`) values (‘$username’,‘$password’)”;

you have to enclose the column names only with symbols (NOT single quote). You can see that symbol just above “TAB” key.