DB will INSERT wont UPDATE..error in code?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



forgive the poor structure of my code, im pretty new at this and havent
figured out exactly what it should be formed like to look its best, anyway
whenever i run this code it works on inserting new information into the
database, however when i want to update the SQL query returns an output like
this 'SQL statement = UPDATE badges (staff,ttlpst,mnthpst,ttlicon,mnthicon)
VALUES ('1','1','1','/ribbons','/ribbons') WHERE fid=2' but when i try to
pull the information from the database it hasnt updated, can someone help me
out with this...im not sure why it wouldnt update even though the statement
looks correct.

 if (empty($form_status)){

$staff = $HTTP_POST_VARS["staff"];
$ttlpst = $HTTP_POST_VARS["ttlpst"];
$mnthpst = $HTTP_POST_VARS["mnthpst"];
$ttlicon = $HTTP_POST_VARS["ttlicon"];
$mnthicon = $HTTP_POST_VARS["mnthicon"];

 $exists = "SELECT * FROM badges WHERE fid = $fid";

 $result = mysql_query($exists);

 if (mysql_num_rows($result) == 0)
 {
 $sql = "INSERT INTO badges (fid,staff,ttlpst,mnthpst,ttlicon,mnthicon)
VALUES ('$fid','$staff','$ttlpst','$mnthpst','$ttlicon','$mnthicon')";
 db_query($sql);
 $form_status = "<span class=\"msgUpdated\">Description
Updated!</span><br>\n";
 }
 else
 {
 $sql = "UPDATE badges SET staff = '".$HTTP_POST_VARS["staff"]."' ttlpst =
'".$HTTP_POST_VARS["ttlpst"]."' mnthpst = '".$HTTP_POST_VARS["mnthpst"]."'
ttlicon = '".$HTTP_POST_VARS["ttlicon"]."' mnthicon =
'".$HTTP_POST_VARS["mnthicon"]."' WHERE fid = $fid";
 db_query($sql);
 $form_status = "<span class=\"msgUpdated\">Description
Updated!</span><br>\n";
 }
}

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux