www.webdeveloper.com
Results 1 to 3 of 3

Thread: UPDATE query. Still a problem...

  1. #1
    Join Date
    Mar 2005
    Posts
    172

    UPDATE query. Still a problem...

    Hi All,

    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 0000-00-00 00:00:00)

    So 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?

    Any ideas?

    Thanks

    PHP Code:
    <?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>

  2. #2
    Join Date
    May 2007
    Location
    Tamalanrea
    Posts
    33
    You can't update TIMESTAMP type field, use DATE TIME instead. I read it somewhere in mysql.org but do not save the URL, you can try search it if you want.

    ----------------------------------------
    http://anaknegri.com http://pajaknenkin.com http://arifkurniawan.net
    http://ppi-kansai.net http://kti2007.ppi-kansai.net

  3. #3
    Join Date
    Mar 2005
    Posts
    172
    Thanks, but i've tried using the above code in both a timestamp and datetime field and the above code does still not update?

    Anyone got any other suggestions?

    Thanks

    Chris

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles