404 Not Found
404 Not Found

Reputation: 1223

Something going wrong with this Query?

i am breaking my head behind it from last 30 mins but i don't where i am doing mistake. i am really got confused between (') and (").

The $arr value contains value that i have checked by printing echo $arr['given_name']. so no doubt in $arr's data.

 $query="insert into user (fname,lname,email,gender) values('".$arr['given_name']."','".$arr['family_name']."','".$arr['email']."','".$arr['gender']."'";
 mysqli_query($con,$query);

i know it's basic question but still i am not able to identify error Can you please suggest me where i am doing mistake?

Upvotes: 0

Views: 70

Answers (4)

stUrb
stUrb

Reputation: 6832

I can imagine you get confused by the brackets, " and '-'s and mis the closing ).

Why don't you use prepared statements? That sorts out your confusing and makes the code way more readable! And you got basic parameter-type checking.

$stmt = $mysqli->prepare("INSERT INTO user 
                          (fname,lname,email,gender) 
                          VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $arr['given_name'], 
                          $arr['family_name'], 
                          $arr['email'], 
                          $arr['gender']);
$stmt->execute();

Also make sure you've got some sanitizing and checks build in your complete query.

Upvotes: 2

Piotr
Piotr

Reputation: 680

Aren't you missing closing ) for inserted values?

Upvotes: 0

Adam Rivers
Adam Rivers

Reputation: 1075

You forgot a closing bracket at the end of the values:

$query="insert into user (fname,lname,email,gender) values('".$arr['given_name']."','".$arr['family_name']."','".$arr['email']."','".$arr['gender']."')";
mysqli_query($con,$query);

Upvotes: 1

user399666
user399666

Reputation: 19879

It should be:

$query="insert into user (fname,lname,email,gender) values('".$arr['given_name']."','".$arr['family_name']."','".$arr['email']."','".$arr['gender']."')";

You're missing an end bracket.

Upvotes: 1

Related Questions