MySql Insert Query Problem
Whats wrong with insert query.
$result = $conn->query("insert into u开发者_StackOverflowser (fullname,username,email,passwd) values
('".$data['fullname']."','".$data['username']."','".$data['email']."','".$data['fullname']."') " );
if(!$result) {
throw new Exception('Could not register you in database - please try again later.');
}
thanks
Mostly detail: you seem to pass fullname into passwd column - not sure if it is intentional.
Otherwise the code seems okay. Var_dump please whole string (with variable values filled in) you are passing into the query method and post it here.
And check the message returned by mysql via mysql_error/mysqli::error.
Also, good practice is to type SQL keywords in uppercase.
Check the message returned by MySQL via mysql_error/mysqli::error
or add this to the end of your MySQL query to see the error on the browser.
die(mysql_error())
Secondly it looks like you are inputting in the wrong field or column
Your query looks fine so it's almost certainty the content of the $data that is causing the error. We can't help you with the specific error unless you provide it.
One thing that comes to mind is that one of those values contains an apostrophe. In that case, you need to sanitize your data, which you should do anyway, in fact, because otherwise you are extremely vulnerable to people hacking your website.
Try using addslashes($data['username'])
instead of just $data['username']
in your query.
addslashes()
adds slashes before characters like apostrophes.
精彩评论