简体   繁体   中英

SQL Inserting Syntax Error

Hey Guys I'm getting a syntax error with my SQL on my PHP page.

Basically what my page does is that it simply inserts data from a form and inserts into the database.

This is my code and my error:

Problem with query.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', '', '', '', '', '')' at line 2

$sql = "INSERT INTO user (username, password, gname, mname, surname, address, state, postcode, tel)
VALUES ( '$usernamestr', '$passwordstr','$firstnamestr', '$middlenamestr’, '$familynamestr', '$addressstr', '$statestr', '$postcodestr', '$phonestr');";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());

I thought this was the way to do it? which is absolutely weird.

You have a funky quote:

VALUES ( '$usernamestr', '$passwordstr','$firstnamestr', '$middlenamestr’, '$familynamestr', 
                                                                       ^^^^
                                                                       HERE

It is a ' and needs to be a ' (as the syntax highlighter shows in my answer but not in your question).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM