Home  >  Article  >  Backend Development  >  Why can't mysql be written like this using update?

Why can't mysql be written like this using update?

WBOY
WBOYOriginal
2016-08-04 09:20:081290browse

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?

Reply content:

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn