1

When I try to send data from an html form to a database using php, I keep getting error unexpected ; in line 6. I cant seem to find the exact cause.

This is the code of send.php:

<?php
//Connecting to sql db.
$connect = mysqli_connect("host","user","password","database");
//Sending form data to sql db.
mysqli_query($connect,"INSERT INTO sw5_green (firstname_r, lastname_r, vid, occupation, address, firstname_s, lastname_s, country, amount, currency) 
VALUES ('$_POST[post_firstname_r]', '$_POST[post_lastname_r]', '$_POST[post_vid]', '$_POST[post_occupation]', '$_POST[post_address]', '$_POST[post_firstname_s]', '$_POST[post_lastname_s]', '$_POST[post_country]', '$_POST[post_amount]', '$_POST[post_currency]')";
?>
1
  • Thanks :) It worked Commented Jul 19, 2016 at 11:41

3 Answers 3

1

You are missing ) at the end of the statement. put ) this before last ;.

Try it,

    mysqli_query($connect,"INSERT INTO sw5_green (firstname_r, lastname_r, vid, occupation, address, firstname_s, lastname_s, country, amount, currency) 
VALUES ('$_POST[post_firstname_r]', '$_POST[post_lastname_r]', '$_POST[post_vid]', '$_POST[post_occupation]', '$_POST[post_address]', '$_POST[post_firstname_s]', '$_POST[post_lastname_s]', '$_POST[post_country]', '$_POST[post_amount]', '$_POST[post_currency]')");
Sign up to request clarification or add additional context in comments.

1 Comment

That's not quite in the right place. Your explanation is right but the code example is wrong.
0

You are missing )

Replace your code with query with this

mysqli_query($connect,"INSERT INTO sw5_green (firstname_r, lastname_r, vid, occupation, address, firstname_s, lastname_s, country, amount, currency) 
VALUES ('$_POST[post_firstname_r]', '$_POST[post_lastname_r]', '$_POST[post_vid]', '$_POST[post_occupation]', '$_POST[post_address]', '$_POST[post_firstname_s]', '$_POST[post_lastname_s]', '$_POST[post_country]', '$_POST[post_amount]', '$_POST[post_currency]'))";

5 Comments

You've copied the same mistake from Vinod VT 's answer. (which he has since corrected).
please just check the time, i just typing the answer and some one given it before few second than its not mean that it copy @SimonShirley
Granted, that may have been the case. The answers and comments were in rapid succession, but it did seem odd that it was exactly the same typo.
if i want to copy than i can just change the description, but when i typing the answer at that time there is no any answers, so i have given that ans .
I'm not going to get into a debate over when things were posted as it's counter-productive. However, I will leave you with one final thought - your code example still contains the typo and therefore will not solve the OP's problem.
0

wrong syntax

'$_POST[post_firstname_r]' should be $_POST['post_firstname_r']

Always escape your data before saving.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.