Jump to content


Photo

insert timestamp onto database problem


  • Please log in to reply
30 replies to this topic

#1 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 10:25 PM

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

#2 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:27 PM

$showdate = date("F j, Y, g:i a");

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

#3 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 10:35 PM

the show date on the page works..it just does'nt go into the DB.
thx
Charlie

#4 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:36 PM

well, how are you submitting it? because if i'm right your sql is incorrect

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

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


#5 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 10:40 PM

tryed that still 0000-00-00 00:00:00
thx
Charlie

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 10:44 PM


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

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 10:51 PM

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

#8 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:52 PM

that's what he has.

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

do that, then edit your sql

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

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

#9 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:53 PM

if you have a form do:

<input type=hidden value='<?php echo $showdate ?>'>


#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 10:54 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:55 PM

he has:

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

#12 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 10:59 PM

this should be your final 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;
}

?>


#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 11:02 PM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 11:05 PM

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;


#15 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 11:07 PM

copy my code

#16 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 11:09 PM

my inserts are the same order as my database m8

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 11:10 PM

post your database please cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 October 2006 - 11:16 PM

id int
name vachar
Cname varchar
email varchar
query varchar
Pnumber varchar
date timestamp

#19 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 05 October 2006 - 11:17 PM

is id primary key w/ auto_increment?

#20 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 October 2006 - 11:18 PM

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

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users