Why won't my mysqli insert/update work

115 Views Asked by At

What is wrong with my coding, since it won't work?

$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

There are 1 best solutions below

2
On

You should really stick to the basics, because your syntax makes no sense. This code makes more sense.

$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') ");
}