我在使用where
子句插入数据时遇到问题。这是查询:
$hi= "INSERT INTO user_detail (email, looking, username, profession, experience,
current_work, state, job_type, about, college, diploma, department)
VALUES ('$email', '$looking', '$username', '$profession','$experience',
'$current_work', '$state', '$job_type', '$about', '$college', '$diploma', '$department')
WHERE s='$username'";
它显示了错误:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第1行'WHERE s ='aniket276'附近
答案 0 :(得分:3)
使用MySQL更新
像那样: -16 --> 14
如果要更改的值,您应该使用UPDATE 您使用WHERE子句选择的记录中的字段
答案 1 :(得分:0)
Word
子句没有任何意义。
如果要在数据库中添加新行,则不需要WHERE
子句,因为没有可以引用的现有行。
如果要更新现有行,则不应使用WHERE
语句,而应使用INSERT
语句。
答案 2 :(得分:0)
插入没有WHERE子句。
如果您只想为特定用户名插入一行,那么最好在您的调用php脚本中执行此操作。
如果要修改特定用户名的现有行,则可以使用更新语句: -
UPDATE user_detail
SET email = '$email',
looking = '$looking',
username = '$username',
profession = '$profession',
experience = '$experience',
current_work = '$current_work',
state = '$state',
job_type = '$job_type',
about = '$about',
college = '$college',
diploma = '$diploma',
department = '$department'
WHERE s = '$username'
如果你想要插入一行,如果它不存在但是如果它存在则更新它然后你可以执行INSERT / ON DUPLICATE KEY UPDATE(假设 s 列为用户名上有唯一索引): -
INSERT INTO user_detail (s,
email,
looking,
username,
profession,
experience,
current_work,
state,
job_type,
about,
college,
diploma,
department)
VALUES ('$username',
'$email',
'$looking',
'$username',
'$profession',
'$experience',
'$current_work',
'$state',
'$job_type',
'$about',
'$college',
'$diploma',
'$department')
ON DUPLICATE KEY UPDATE email = VALUES(email),
looking = VALUES(looking),
username = VALUES(username),
profession = VALUES(profession),
experience = VALUES(experience),
current_work = VALUES(current_work),
state = VALUES(state),
job_type = VALUES(job_type),
about = VALUES(about),
college = VALUES(college),
diploma = VALUES(diploma),
department = VALUES(department)
答案 3 :(得分:0)
要插入新记录,请不要使用WHERE。当你想引用特定记录时,你在哪里。为此,您可以使用MySQL Update。
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value