Jump to content

[SOLVED] GET problem...


Mr Chris

Recommended Posts

Hi Guys,

 

I was wondering if someone can help me with an update problem. 

 

Basically in my content management system I want to be able to call a date and time from a database record and show those values in two textboxes for the user to update them:

 

However.  In my cms the date and time is saved in one field named: web_date_time (timestamp) ie: 2007-04-26 09:43:48

 

So what I want to do, is when I GET a record it splits up the web_date_time and places them in two different textboxes as shown below.

 

Can anyone help.

 

Thanks

 

Chris

 

<?php

// ** Get the requested story id from the database **
if(isset($_GET['story_id'])) 
{ 
    $result = mysql_query("Select * From cms_stories2 where story_id=".$_GET['story_id']); 
    $row = mysql_fetch_array($result); 
    $web_date_time = $row['web_date_time'];

} 

// ** 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 = mysql_query("UPDATE cms_test set web_date_time='$web_date"." "."$web_time' where story_id=".$_GET['story_id']);
header('Location: edit_list.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(); 

} 
}
?>

<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 NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date?>" SIZE="48">
  </p>
  <p>
    Time: 
    <INPUT NAME="web_date" TYPE="text" ID="web_time" VALUE="<?php echo $web_time?>" SIZE="48">
  <p>
    <input type="Submit" name="Submit" value="Submit">
  </p>
  </form>

 

 

Link to comment
Share on other sites

check name of time textbox

 

<INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date?>" SIZE="48">

  </p>

  <p>

    Time:

    <INPUT NAME="web_date[ This should be web_time]" TYPE="text" ID="web_time" VALUE="<?php echo $web_time?>" SIZE="48">

Link to comment
Share on other sites

Thanks, but still a bit confused

 

So do you mean something like this:

 

<?php

// ** Get the requested story id from the database **
if(isset($_GET['story_id'])) 
{ 
    $result = mysql_query("Select * From cms_stories2 where story_id=".$_GET['story_id']); 
    $row = mysql_fetch_array($result); 

    $web_date_time = $row['web_date_time'];

} 

// ** 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 = mysql_query("UPDATE cms_test set web_date_time='$web_date"." "."$web_time' where story_id=".$_GET['story_id']);
header('Location: edit_list.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(); 

} 
}
?>

<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 NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date_time = date(Y-m-d); ?>" SIZE="18">
  </p>
  <p>
    Time: 
    <INPUT NAME="web_time" TYPE="text" ID="web_time" VALUE="<?php echo $web_date_time = date(H:i:s); ?>" SIZE="18">
  <p>
    <input type="Submit" name="Submit" value="Submit">
  </p>
  </form>

 

So when I get a record from the database the record gets the web_date_time and then splits this timestamp value into both the web_date and web_time textboxes?

 

Or am I undertsanding it wrong?

Link to comment
Share on other sites

if(isset($_GET['story_id']))

{

    $result = mysql_query("Select * From cms_stories2 where story_id=".$_GET['story_id']);

    $row = mysql_fetch_array($result);

    // Assume $row['web_date_time'] has such kind of type 2007-05-10 12:12:10

   

    $date_time_array = explode(" ",$row['web_date_time']);

    $web_date =  $date_time_array[0];

    $web_time = $date_time_array[1];

    echo $web_date ;

    echo $web_time ;

}

p> Date:

<INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo $web_date ;?>" SIZE="18">

  </p>

  <p>

    Time:

    <INPUT NAME="web_time" TYPE="text" ID="web_time" VALUE="<?php echo $web_date ;?>" SIZE="18">

  <p>

Link to comment
Share on other sites

Date:

<INPUT NAME="web_date" TYPE="text" ID="web_date" VALUE="<?php echo date("Y-m-d", strtotime($web_time)); ?>" SIZE="48">

Time:

<INPUT NAME="web_date" TYPE="text" ID="web_time" VALUE="<?php echo date("H:i:s", strtotime($web_time)); ?>" SIZE="48">

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.