0

Can someone help me entering a date "manually" in MySQL thanks :) here's my code it's currently entering 0000-00-00 in my databse

THE HTML

<html>
<head>
<title>..</title>
<body>
<form action="work1.php" method="post">
Value1: <input type="text" name="date"><br>
<input type="Submit">
</form>
</body>
</head>
</html>

PHP

<?php
$username="root";
$password="";
$database="wapwap";

$date=$_POST['Value1'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");

$query = "INSERT INTO date VALUES
('','$date')";

mysql_query($query);

mysql_close();
?>

NEW to PHP :)

4
Contributors
10
Replies
11
Views
7 Years
Discussion Span
Last Post by niths
0

Your Date is coming as a String.Due to this , it is displaying 0000-00-00.

Solution is.....

$date=$_POST['Value1'];

---- This is the String.
After taking the date value as a string convert the string with date format.

0

You should use the name of the element not the label

Day:<input type="text" name="dy"><br>
Month:<input type="text" name="mth"><br>
Year:<input type="text" name="yr"><br>

in PHP

$dy = $_POST['dy'];
$mth=$_POST['mth'];
$yr = $_POST['yr'];
$phpdate = $yr."-".$mth."-".$dy;
$phpdate=date($phpdate);

Edited by rajarajan07: n/a

0

@Ankit Parmar: Exactly how will i do it? i've searched strtotime() but can you show me how?

After taking the date value as a string convert the string with date format.

@rajarajan07: What I wanted to happen is that to enter a date (i.e. 2010-07-29 which is yyyy-mm-dd) in the textbox and that it will instantly be inserted in MySQL. Well is that ever possible, or I really do need to have separate textboxes for month day and year?

Thanks Experts.

Edited by ekseks: n/a

0

Here's my current code found something on the internet about strtotime, and yes it's entring a data in my database but... but it's 01/01/1970 why is that?

<?php
$username="root";
$password="";
$database="matuto";

//$date=$_POST['Value1'];

$new_date = date("m/d/Y", strtotime($date));

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");

$query = "INSERT INTO datemonga VALUES
('','$new_date')";

mysql_query($query);

mysql_close();
?>
0

//$date=$_POST; --- Don't comment this line.Because you want to store this value.

$new_date = date("m/d/Y", strtotime($date)); In This line , What is the value of $date. Becoz,You are commenting Previoue line.

That'why , it is storing 01-01-1970(this is initial date value).

0

I'm trying to get my input in my textbox, the one on my html code

Value1: <input type="text" name="date">

Of course, inserting manually in my php code will work but I wanted to get the value that I inserted in my textbox and upon clicking SUBMIT it will store the date in my database

Edited by ekseks: n/a

0
<html>
<head>
<title>..</title>
<body>
<form action="work1.php" method="post">
Value1: <input type="text" name="date"><br>
<input type="Submit"/>
</form>
</body>
</head>
</html>
<?php
$username="root";
$password="abcdef";
$database="test_date";
$date=$_POST["date"];  // Your First Problem Post value
echo $date;
echo "i m here";
$date = date("Y/m/d", strtotime($date));   // 2nd Problem Date Format
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");

$query = "INSERT INTO date VALUES('','$date')";

mysql_query($query);

mysql_close();
?>

It's Working .

Change according to this.

0

ok, i had a question for you. Do you want to insert into database the current date...?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.