通过PHP更新SQL中的记录

时间:2014-05-23 12:56:12

标签: php

如何从数据库更新记录?

$query = "UPDATE studentinfo SET firstname= '".$student['fname']."' and lastname='".$student['faname']."' and gender = 'Male' WHERE id = '".$student['id']."'"; 

3 个答案:

答案 0 :(得分:2)

UPDATE table SET column1 = 'value1', column2 = 'value2'

不要使用AND来分隔SET子句中的术语。

答案 1 :(得分:1)

$query = "UPDATE studentinfo SET firstname= '".$student['fname']."', lastname='".$student['faname']."', gender = 'Male' WHERE id = '".$student['id']."'";

答案 2 :(得分:1)

ANDSQL中用于多个条件。

要更新多个字段,只需用逗号分隔:

$query ="UPDATE studentinfo 
SET firstname = '$student['fname']', lastname = '$student['faname']', gender = 'Male'
WHERE id = '$student['id']'";