0

I am trying to insert the Name and Surname into an User table I created using mysql. The process.php file that has to insert the data throws a syntax error on line 10 (the " just before the INSERT):

Parse error: syntax error, unexpected ' " ', expecting ' , ' or ' )'

What is the problem? Here is my code:

<?php include 'database.php';


// create a variable
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];


//Execute the query
mysqli_query ($connect"INSERT INTO User(Name, Pass)
                VALUES('$first_name','$last_name')");

?> 
Alonso
  • 141
  • 4
  • 12
  • Why did you tag this with `jquery`? – John Conde Apr 26 '17 at 18:22
  • 1
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). – John Conde Apr 26 '17 at 18:22
  • 1
    Please do not abuse the code snippet tool. It's for HTML/JS/CSS only. – John Conde Apr 26 '17 at 18:23
  • 1
    You're missing a comma. – John Conde Apr 26 '17 at 18:23
  • 1
    put a comma after your "$connect"`//Execute the query mysqli_query ($connect,"INSERT INTO User(Name, Pass) VALUES('$first_name','$last_name')");` And try to comprehend your error next time or else you'll be back here a lot – rm-vanda Apr 26 '17 at 18:24
  • Thanks, it worked! – Alonso Apr 26 '17 at 18:26
  • 1
    plus that the use of any proper tool with 'syntax highlighting' (don't know how to say that correctly in english...) would show you this – OldPadawan Apr 26 '17 at 18:30

1 Answers1

0

Use this

mysqli_query ($connect,"INSERT INTO User(Name, Pass)
            VALUES('$first_name','$last_name')");
Manav Sharma
  • 187
  • 1
  • 8
  • Please don't post answers on obviously off-topic questions! [See: **Should one advise on off topic questions?**](http://meta.stackoverflow.com/q/276572/1768232) Off-topic questions can be closed and deleted, which could nullify your contribution. – John Conde Apr 26 '17 at 18:24
  • While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-‌​code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. You should read, "[How do I write a good answer?"](http://stackoverflow.com/help/how-to-answer) – John Conde Apr 26 '17 at 18:24
  • Who upvoted this? – John Conde Apr 26 '17 at 18:28
  • Can you please explain me John, what i write wrong in my post? – Manav Sharma Apr 26 '17 at 18:29
  • Both of you where correct: the comma was missing. Thanks – Alonso Apr 26 '17 at 18:30
  • This is a simple typo/syntax error which are low quality and should be closed as such. You should not be answering them. See [this](//meta.stackoverflow.com/questions/347937/) as to why not. – John Conde Apr 26 '17 at 18:30