我在用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=‘aniket276’”附近的正确语法。
发布于 2015-10-30 13:53:48
使用MySQL更新
就像这样:-
UPDATE user_detail SET email='$email' WHERE s='$username';如果要使用WHERE子句更改所选记录中字段的值,则应该使用UPDATE。
发布于 2015-10-30 13:53:42
insert中的WHERE子句不会产生任何意义。
如果要向数据库中添加新行,则不需要WHERE子句,因为没有可以引用的现有行。
如果要更新现有行,则不应使用INSERT语句,而应使用UPDATE语句。
发布于 2015-10-30 14:02:31
插入没有WHERE子句。
如果您只想为特定的用户名插入一行,那么最好在您的调用php脚本中这样做。
如果要修改特定用户名的现有行,则需要使用update语句:
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'如果不存在行,则要插入行,但如果行存在,则可以进行插入/对重复键的更新(假设用户名的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)https://stackoverflow.com/questions/33437626
复制相似问题