为什么我的mysqli插入/更新不起作用

时间:2013-12-10 20:19:06

标签: php mysqli insert-update

我的编码有什么问题,因为它不起作用?

$empsql("SELECT * FROM employees WHERE e_id ='$ed_id' ");

if($rows > 0)  {
    $empsql('UPDATE employees SET name = "'.$name.'" , description = "'.$description.'" , telephone = "'.$telephone.'" , email = "'.$email.'" WHERE e_id = "'.$ed_id.'" ');
}
else
{
    $empsql("INSERT INTO employees (name,description,telephone,email) VALUES ('$name','$description','$telephone','$email') ");
}

1 个答案:

答案 0 :(得分:0)

你应该坚持基础,因为你的语法没有意义。这段代码更有意义。

$empsql = "SELECT * FROM employees WHERE e_id ='$ed_id'";
$rows = mysql_fetch_array(mysql_query($empsql));

if(!empty($rows))  {
    mysql_query('UPDATE employees SET name = "'.$name.'" , description = "'.$description.'" , telephone = "'.$telephone.'" , email = "'.$email.'" WHERE e_id = "'.$ed_id.'" ');
}
else
{
    mysql_query("REPLACE INTO employees (name,description,telephone,email) VALUES ('$name','$description','$telephone','$email') ");
}