Jump to content

Archived

This topic is now archived and is closed to further replies.

2wasted

insert timestamp onto database problem

Recommended Posts

lo all,
i have a form that goes to a database, everthing works fine except the timestamp says 0000-00-00 00:00:00 .i have tryed changing the value in the mysql from timestamp to date but still is'nt working...i have displayed the date on my page np...here is the code
?PHP
    $Name=$_POST['name'];
$Cname=$_POST['cname'];
$Query=$_POST['Question'];
$email=$_POST['email'];
$Pnumber=$_POST['Pnumber'];
$date = time();
$showdate = date("H:i:s d/m/Y");
mysql_select_db($database_csc, $csc);
$query_Recordset1 = "SELECT * FROM onlineform";
$Recordset1 = mysql_query($query_Recordset1, $csc) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$query_Recordset1 or die( "Unable to select database");
if($_POST['submit']) {

$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query', '$Pnumber', '$date')";
mysql_query($query);

mysql_close();


  echo "<h2>THank you for filling in this form, we will be in touch with you ASAP</h2>";
  echo $showdate;
}

?>
Thanks for any help
Charlie

Share this post


Link to post
Share on other sites
[code]
$showdate = date("F j, Y, g:i a");
[/code]

It'll show like "October 5, 2006, 5:29 pm"

Share this post


Link to post
Share on other sites
well, how are you submitting it? because if i'm right your sql is incorrect

[code]
$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query', '$Pnumber', '$date')";
[/code]

should be:
[code]
$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query', '$Pnumber', '$showdate')";
[/code]

Share this post


Link to post
Share on other sites

[code]
$query = "INSERT INTO onlineform VALUES ('$name','$Cname','$email','$Query', '$Pnumber', '$date')";
mysql_query($query);
[/code]

Share this post


Link to post
Share on other sites
i took out the echo $showdate; and it still never worked. i have tryed values of date&timestamp in the mysql database structure, could i use another?
Charlie

Share this post


Link to post
Share on other sites
that's what he has.

did you change the $showdate to [code]$showdate = date("F j, Y, g:i a");[/code]

do that, then edit your sql

[code]
$query = "INSERT INTO onlineform VALUES ('$name','$Cname','$email','$Query', '$Pnumber', '$showdate')";
mysql_query($query);
[/code]

you had $date while $date = time();, showdate is the date

Share this post


Link to post
Share on other sites
if you have a form do:

[code]
<input type=hidden value='<?php echo $showdate ?>'>
[/code]

Share this post


Link to post
Share on other sites
you got the insert set as date so you need to set $date=date();

dont you.

you got showdate but the insert looking for $date.

Share this post


Link to post
Share on other sites
he has:

$date = time();
and $showdate = date();

Share this post


Link to post
Share on other sites
this should be your final code

[code]
<?PHP
    $Name=$_POST['name'];
  $Cname=$_POST['cname'];
  $Query=$_POST['Question'];
  $email=$_POST['email'];
  $Pnumber=$_POST['Pnumber'];
  $date = time();
  $showdate = date("F j, Y, g:i a");
mysql_select_db($database_csc, $csc);
$query_Recordset1 = "SELECT * FROM onlineform";
$Recordset1 = mysql_query($query_Recordset1, $csc) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$query_Recordset1 or die( "Unable to select database");
if($_POST['submit']) {

$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query', '$Pnumber', '$showdate')";
mysql_query($query);

mysql_close();


  echo "<h2>THank you for filling in this form, we will be in touch with you ASAP</h2>";
  echo $showdate;
}

?>[/code]

Share this post


Link to post
Share on other sites
I have had a good look know and your insert is wrong as the insert has to be in the same order as the database and yours isint.

have a look at you database field order and match aginst you insert on here the order i think is wrong  sorry.

Share this post


Link to post
Share on other sites
this is what i have changed it to and it still does'nt work

        $Name=$_POST['name'];
$Cname=$_POST['cname'];
$Query=$_POST['Question'];
$email=$_POST['email'];
$Pnumber=$_POST['Pnumber'];
$date = time();
$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query', '$Pnumber', '$showdate')";
mysql_query($query);

mysql_close();


  echo "<h2>THank you for filling in this form, we will be in touch with you ASAP</h2>";
  //echo $showdate;

Share this post


Link to post
Share on other sites
id int
name vachar
Cname varchar
email varchar
query varchar
Pnumber varchar
date timestamp

Share this post


Link to post
Share on other sites
[code]
<?php

   $Name=$_POST['name'];
   $Cname=$_POST['cname'];
   $Query=$_POST['Question'];
   $email=$_POST['email'];
   $Pnumber=$_POST['Pnumber'];
   $date = time();
   $showdate = date("H:i:s d/m/Y");


mysql_select_db($database_csc, $csc);

$query_Recordset1 = "SELECT * FROM onlineform";

$Recordset1 = mysql_query($query_Recordset1, $csc) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$query_Recordset1 or die( "Unable to select database");

if($_POST['submit']) {

$query = "INSERT INTO onlineform VALUES ('$id','$name','$Cname','$email','$Query', '$Pnumber', '$date')";

mysql_query($query)or die("insert is dead");


echo "<h2>THank you for filling in this form, we will be in touch with you ASAP</h2>";
echo $showdate;

}

?>
[/code]

Share this post


Link to post
Share on other sites
[code]
$query = "INSERT INTO onlineform (name,Cname,email,query,Pnumber,date) VALUES ('$name','$Cname','$email','$Query', '$Pnumber', '$date')";
[/code]

try that

Share this post


Link to post
Share on other sites
[quote author=mgallforever link=topic=110633.msg447638#msg447638 date=1160090242]
is id primary key w/ auto_increment?
[/quote]
yeah m8

Share this post


Link to post
Share on other sites
[quote author=mgallforever link=topic=110633.msg447643#msg447643 date=1160090496]
[code]
$query = "INSERT INTO onlineform (name,Cname,email,query,Pnumber,date) VALUES ('$name','$Cname','$email','$Query', '$Pnumber', '$date')";
[/code]

try that
[/quote]
still the same m8

Share this post


Link to post
Share on other sites
my god, why is there such a big problem on this

just do it EXACTLY like this

copy the variable code I give you

this is how I did it on my news script

[code]
$timestamp = date('M j, Y  g:i A');
[/code]

then just insert $timestamp into your date field

it's very simple actually.

Share this post


Link to post
Share on other sites
hes not posting show date is he.

$showdate=$_POST['showdate'];
$date=$_POST['date'];

Share this post


Link to post
Share on other sites

×

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.