Jump to content

'Update' question


BadGoat

Recommended Posts

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:
[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'";[/code]

I'm not sure what I did to futz up this easy little script :(
Link to comment
Share on other sites

You're not actually doing an update. You're just defining a query string. You need to call mysql_query() with the query sting.
[code]<?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());
?>[/code]

Ken
Link to comment
Share on other sites

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:
[code]
        $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>';
        }
    }
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.