Jump to content

Recommended Posts

Hi,

 

When i'm grabbing a row from my database and then trying to UPDATE those details it's not updating and I don't see why:

 

DB Structure

story_id (int 1)

published_web_date_time (timestamp / datetime 0000-00-00 00:00:00)

 

Now in the structure above i've tried both published_web_date_time as both a timestamp and datetime field as I was told you can't update a timestamp field in MYSQL using PHP, which I thought was wierd?  But nomatter what I change published_web_date_time to field wise it still does not update.

 

If you look at my form below when I GET the data I get the published_web_date_time split into two textfields as shown in the form below, but when it comes to updating these textfields with new values it does not save the data to the database upon sumbit?

 

Any ideas?

 

Thanks

 

<?php


// ** Get the requested story id from the database **
if(isset($_GET['story_id'])) 
{ 
    $result = mysql_query("Select * From cms_test where story_id=".$_GET['story_id']); 
    $row = mysql_fetch_array($result); 
    $date_time_array = explode(" ",$row['published_web_date_time']);
    $published_web_date =  $date_time_array[0];
    $published_web_time = $date_time_array[1];	
} 

// ** If Submit is hit do your stuff **
    if (isset($_POST['Submit'])) {

    $published_web_date_time = $_POST['published_web_date_time'];

// ** Check for Required Fields with IF statements **
       if (empty($published_web_date)){
        $error = "** no time! **"; 
   	}  else if (empty($published_web_time)){
        $error = "** no date! **";

// ** If all of the statements are true then **
    } else {
    $query = mysql_query("Update cms_test set published_web_date_time='$published_web_date $published_web_time' where story_id=".$_GET['story_id']); 
header('Location: done.php');  

// ** And finally run the query to add data to the database **
     $link = mysql_connect;
     $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 
     mysql_close(); 

} 
}
?>
<FORM ACTION="".php" method="post" NAME="frmAdd">

  Date: <INPUT NAME="published_web_date" TYPE="text" ID="published_web_date" VALUE="<?php echo $published_web_date?>" SIZE="18">
   <br />
   <br / >
  Time: <INPUT NAME="published_web_time" TYPE="text" ID="published_web_time" VALUE="<?php echo $published_web_time?>" SIZE="18"><br />
   <br />
  <INPUT TYPE="Submit" NAME="Submit" VALUE="Submit" CLASS="button">
</form>

 

Link to comment
https://forums.phpfreaks.com/topic/51051-update-timestamp-or-datetime/
Share on other sites

Thanks Des, but I don't understand what you mean by that.  If I have 120 records in my database and I am pulling out one record random i'm not going to know the date and time (timestamp or datetime) for each record.

 

So is there no way of using UPDATE in the code i've posted then?

 

Chris

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.