Jump to content

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
https://forums.phpfreaks.com/topic/23122-insert-timestamp-onto-database-problem/
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]
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
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]
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.
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;
[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]
[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
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.
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.