Jump to content


Photo

'Update' question


  • Please log in to reply
2 replies to this topic

#1 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 13 October 2006 - 07:19 PM

Hello!

I am trying to update a field in the database which is not working. It is a date field, which is not updating. There are two other fields in the update script which work fine, the $updated however, does not change. As a matter of fact, it erases the date that is in the db and leaves it blank. My code:
<input type="hidden" name="newupdated" value="' .$updated. '">
';
$updated=date('M j Y');
$query = "UPDATE record SET  nic = '".escapeSingleQuotes($_REQUEST['newnic'])."', company_id = '".$_REQUEST['newcompany_id']."', updated = '".$_REQUEST['newupdated']."' WHERE id='$id'";

I'm not sure what I did to futz up this easy little script :(


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 October 2006 - 07:30 PM

You're not actually doing an update. You're just defining a query string. You need to call mysql_query() with the query sting.
<?php
$query = "UPDATE record SET  nic = '".escapeSingleQuotes($_REQUEST['newnic'])."', company_id = '".$_REQUEST['newcompany_id']."', updated = '".$_REQUEST['newupdated']."' WHERE id='$id'";
$rs = mysql_query($query) or die("Could not update the database, query: $query<br>" . mysql_error());
?>

Ken

#3 BadGoat

BadGoat
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 13 October 2006 - 07:34 PM

My fault, I should have included more of the code. I was hoping my error was glaring. I should note that the script works fine updating the other two variables, the one which does not update is the '$updated' field. immediately following the $query line is this:
        $result = mysql_query($query) or die("<b>mySQL Error:</b>");
        if(!$result)
        {
            echo 'Error processing request.';
        }
        else
        {
            echo '<B>The Record has been successfully updated!</B>';
        }
    }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users