在php中更新数据库表中的记录

时间:2013-04-17 04:24:54

标签: php

我试图通过从另一个.php文件中获取id来更新表中的记录。但是它无法更新。请帮助。这是我的代码。

<?php
include('connection.php');
$member_id = $_GET['id']; 
echo ("You are going to edit/update record of employee with id #");echo $member_id;

if(isset($_REQUEST['submit']))
{
    $firstname =$_REQUEST['firstname'];
    $lastname =$_REQUEST['lastname'];
    $phone =$_REQUEST['phone'];    
    $insert = "update emp set SET firstname ={'$firstname'}, lastname = {'$lastname'} phone = {'$phone'} WHERE id = {'$member_id'}";
    mysql_query($insert);
}


?>

1 个答案:

答案 0 :(得分:2)

此处您有两个SET因为该查询失败,您在,之前忘记了phone = {

$insert = "update emp set SET firstname ={'$firstname'}, lastname = {'$lastname'} phone = {'$phone'} WHERE id = {'$member_id'}";

应该是

$insert = "update emp SET firstname ={'$firstname'}, lastname = {'$lastname'}, phone = {'$phone'} WHERE id = {'$member_id'}";

修改

写这个来检查错误

mysql_query($insert) OR die(mysql_error());