Jump to content

Recommended Posts

Hi All,

 

I'm posting data into a MYSQL database, which works fine using the schema below and the php form below:

 

cms_test

story_id (int 3)

web_date (date)

web_time (time)

 


<?php

// ** POST DATA **
    if (isset($_POST['Submit'])) {

    $web_date = $_POST['web_date'];
$web_time = $_POST['web_time'];

// ** Check for Required Fields with IF statements **
       if (empty($web_date)){
        $error = "** No Pub web date! **"; 
}  else if (empty($web_time)){
        $error = "** No web time **";

// ** If all of the statements are true then **
    } else {	
$query = "INSERT INTO cms_test(published_web_date,published_web_time) VALUES
    ('$web_date','$web_time')";
    $query = mysql_query($query);
    $story_id=mysql_insert_id();
    header("Location: done.php?story_id=$story_id"); 

// ** 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(); 

} 
}
?>
<html>
<head>
<title>Time & Date</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<FORM ACTION="".php" method="post" NAME="frmAdd">
  <p> Date: 
    <input type="text" size="48" maxlength="255" name="web_date" <?php if(isset($web_date)) echo "value='$web_date'"; ?>/>
  </p>
  <p>
    Time: 
    <input type="text" size="48" maxlength="255" name="web_time" <?php if(isset($web_time)) echo "value='$web_time'"; ?>/>
  <p>
    <input type="Submit" name="Submit" value="Submit">
  </p>
  </form>

 

However, i've now normalized my database in the following format:

 

cms_test

story_id (int 3)

web_date_time (timestamp)

 

So my question is how can I modify the form above to post two values ie web_date and web_time, but this time these values are JUST saved in one field - web_date_time in the format: 0000-00-00 00:00:00

 

Thanks

 

Chris

Thanks Guys,

 

But I don't quite understand.  Do you mean something like:

 

<?php

// ** POST DATA **
    if (isset($_POST['Submit'])) {

    $web_date = $_POST['web_date'];
$web_time = $_POST['web_time'];

// ** Check for Required Fields with IF statements **
       if (empty($web_date)){
        $error = "** No Pub web date! **"; 
}  else if (empty($web_time)){
        $error = "** No web time **";

// ** If all of the statements are true then **
    } else {	
$query = "INSERT INTO cms_test(web_date_time) VALUES
    ('$web_date$web_time')";
    $query = mysql_query($query);
    $story_id=mysql_insert_id();
    header("Location: done.php?story_id=$story_id"); 

// ** 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(); 

} 
}
?>
<html>
<head>
<title>Time & Date</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<FORM ACTION="".php" method="post" NAME="frmAdd">
  <p> Date: 
    <input type="text" size="48" maxlength="255" name="web_date" <?php if(isset($web_date)) echo "value='$web_date'"; ?>/>
  </p>
  <p>
    Time: 
    <input type="text" size="48" maxlength="255" name="web_time" <?php if(isset($web_time)) echo "value='$web_time'"; ?>/>
  <p>
    <input type="Submit" name="Submit" value="Submit">
  </p>
  </form>

 

IE the change is where my INSERT query is.  That does insert a new record into the database, but enters everything as 0000-00-00 00:00:00?

 

Thanks

 

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.