Home > Article > Backend Development > Why can't mysql be written like this using update?
Write like this
if(!mysql_query("update kxwr
(name
,sex
,old
) values ('Xiaoming','male','18') where id
='1'")){
exit('Modification failed');
}
echo'The modification was successful! ';
Why does it return failure?
If
if(!mysql_query("insert into kxwr
(name
,sex
,old
,id
) values ('Xiaoming','male','18','1')")) {
exit('Add failed');
}
echo'Added successfully! ';
In this way, insert can be successful but update cannot. Why?
Write like this
if(!mysql_query("update kxwr
(name
,sex
,old
) values ('Xiaoming','male','18') where id
='1'")){
exit('Modification failed');
}
echo'The modification was successful! ';
Why does it return failure?
If
if(!mysql_query("insert into kxwr
(name
,sex
,old
,id
) values ('Xiaoming','male','18','1')")) {
exit('Add failed');
}
echo'Added successfully! ';
In this way, insert can be successful but update cannot. Why?
Wrong grammar
<code>$sql=" UPDATE kxwr SET name='小明' sex ='男' old ='11' WHERE id='1' ";</code>
Grammar issues. update table_name set column1=xxx where column2=yyy;
This is right
Learn sql first.
update is not used like that