1

我正在尝试为用户创建一个简单的插入语句......但它出错了......我只尝试了值并且它有效,它必须与我在插入语句中处理数组的方式有关?

有任何想法吗?

                if ($new_user_data) {
                    $mysqli->query("INSERT INTO users (user_name, user_year, user_sex, user_pic, user_level, user_password, user_email)
                                    VALUES ( ". $new_user_data['user_name'] .",". $new_user_data['user_year'] .",". $new_user_data['user_sex'] .",". $new_user_data['user_pic'] .",1,". $new_user_data['user_password'] .",". $new_user_data['user_email'] ." )");
                    print_r($mysqli->error);
                }

错误:

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 '@gmail.coms )' at line 2
4

1 回答 1

3

您需要将字符串用引号括起来:

$mysqli->query("INSERT INTO users (user_name, user_year, user_sex, user_pic, user_level, user_password, user_email)
                VALUES ( '". $new_user_data['user_name'] ."','". $new_user_data['user_year'] ."','". $new_user_data['user_sex'] ."','". $new_user_data['user_pic'] ."',1,'". $new_user_data['user_password'] ."','". $new_user_data['user_email'] ." )'");

我知道我看不到你所有的代码,但看起来你对 SQL 注入很开放。

于 2013-02-21T15:34:12.150 回答