Jump to content

Recommended Posts

Hello, I have created a very basic form that inserts user information to a MySql Table. I am now trying to make it insert the current date into a Date column within the table.

 

Here is my code:

 

<?php


mysql_connect("mysql9.000webhost.com", "a3313201_admin", "xxxxxx") or die(mysql_error()); mysql_select_db("a3313201_admin") or die(mysql_error()); 

$Username = $_POST['Username'];
$Password= $_POST['Password'];


$query="INSERT INTO Users (Username, Password, [b]DateJoin[/b])VALUES('".$Username."', '".$Password."', [b]???[/b])";

mysql_query($query) or die ('Error 101');

echo "Accoount Created";

?>

 

Thank you for your help

 

<?php
mysql_connect("mysql9.000webhost.com", "a3313201_admin", "xxxxxx") or die(mysql_error()); mysql_select_db("a3313201_admin") or die(mysql_error()); 

$Username = $_POST['Username'];
$Password= $_POST['Password'];
$DateJoin= $_POST['DateJoin'];

$query="INSERT INTO Users (Username, Password, DateJoin) VALUES ('".$Username."', '".$Password."', '".$DateJoin."')";
mysql_query($query) or die ('Error 101');

echo "Accoount Created";

?>

 

While in the form where you $_POST the username and password add this as a hidden field:

<input type="hidden" name="DateJoin" id="DateJoin" value="<?php echo date('Y-m-d H:i:s'); ?>" />

 

Now the date('Y-m-d H:i:s'); is to be used if you have the column

DateJoin

in the sql table set as a DateTime.

 

fugix's solution is another way. Both ways work.

You wouldn't pass a server-side produced value through the form, because that would just add another piece of external modifiable data that you must validate and escape before putting it into the query statement.

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.