Jump to content

insert timestamp onto database problem


2wasted

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
Link to comment
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]
Link to comment
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
Link to comment
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]
Link to comment
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;
Link to comment
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]
Link to comment
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
Link to comment
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.
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.