Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

convert from insert to update (mysql data)

Avatar of Johnny
JohnnyFlag for United States of America asked on
16 Comments1 Solution479 ViewsLast Modified:
i had came across this nifty script a bit back but i now have need to make it update instead of insert
can someone help me convert this so it can be used on a an edit for please

i need to pass the value of
where ID='".$id."'

please see snip attached

thank you in advance  for any code or help you may provide

function quote_smart($val)
    if( is_array($val) ) {
        return array_map("quote_smart", $val);
    } else {
        if( get_magic_quotes_gpc() ) {
            $val = stripslashes($val);
        if( $val == '' ) {
            //$val = 'No Description Available';
            $val = '';
        } if( !is_numeric($val) || $val[0] == '0' ) {
            $val = "'".mysql_real_escape_string($val)."'";
        return $val;

$dontUse = array("submit");
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
      if (!in_array($key,$dontUse)){      if($keyStr) $keyStr.=',';
      $keyStr.= str_replace(')','',$key);
      if($valStr) $valStr.=',';
      $valStr.= quote_smart($val);
      $message .=" $key &nbsp;=&nbsp; $val<br>\n";
      //echo $message;
// Enter Info into the Database.
// where ID='".$id."' <<< need clause
$insert = "INSERT INTO $TableName($keyStr) VALUES($valStr)";
mysql_query ($insert, $mysql_link)
or die(mysql_error());

while($i <= 4)
  if($HTTP_POST_VARS["item$i"] != NULL)
    if($count == 0)
      $items .= $HTTP_POST_VARS["item$i"];
      $items .= ",".$HTTP_POST_VARS["item$i"];

Avatar of Greg Alexander
Greg AlexanderFlag of United States of America imageLead Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answers