这个sql请求是否正确?

时间:2014-04-05 21:08:16

标签: php mysql

我最近遇到了一些Ajax + php注册问题。 我最终得出的结论是,所有问题的根源都会出现在sql请求中。任何人都可以看一下吗?

$insert_new_user=mysql_query("INSERT INTO users (fname,lname,email,password,age,sex,city,timereg,frcode) VALUES('$fname_received','$lname_received','$email_received','$password_received','$dob_received','$sex_received','$city_received,'$timepassreg','$frcode')");

3 个答案:

答案 0 :(得分:0)

$insert_new_user = mysql_query("INSERT INTO `users` (`fname`,`lname`,`email`,`password`,`age`,`sex`,`city`,`timereg`,`frcode`) VALUES ('".$fname_received."','".$lname_received."','".$email_received."','".$password_received."','".$dob_received."','".$sex_received."','".$city_received."','".$timepassreg."','".$frcode."')");

您错过了'附近的$city_received

还要确保您逃避用户输入。

答案 1 :(得分:0)

$ city_received

后缺少报价

答案 2 :(得分:-1)

假设您已转义并检查了变量的有效输入,您似乎只是忘记了'附近的,'$city_received,

<?php
$insert_new_user = mysql_query("
INSERT INTO users
    (fname, lname, email, password, age, sex, city, timereg, frcode)
VALUES
    ('$fname_received', '$lname_received', '$email_received', '$password_received', '$dob_received', '$sex_received', '$city_received', '$timepassreg', '$frcode')
");