dave
07-09-2005, 04:48 PM
Hello,
I have an HTML form with a simple date in it. The form inputs the date as m/d in a field named "ds". How do I format the contents of this field so I can store it in a MySQL Date field in my table?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Shipping Notify</title>
<?php
function escape_data ($data) { // Makes data ok for inserting into MySQL tables
global $dbc; // need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
}
$now = date ('n\\\j');
?>
</head>
<body background="back2.jpg">
<?php
define ('DB_USER', '########');
define ('DB_PASS', '################');
define ('DB_HOST', 'localhost');
/* Database Connect */
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASS) or die ('Could not connect to MySQL: ' . mysql_error() );
$db_name = 'my_db';
@mysql_select_db($db_name) or die ('Could not select the database: ' . mysql_error() );
$ds = stripslashes($ds);
/* Store info into my_db:table */
$tbl_name = "table";
/* Prepare data for saving into MySQL */
$ds = escape_data($ds);
/* build the MySQL INSERT query */
$query = "INSERT INTO $tbl_name (date_shipped) VALUES ('$ds')";
$result = @mysql_query($query) or die (' Could not insert record into db: ' . mysql_error() );
?>
<form action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post" name="foo" style="background-image:url('back.jpg')">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>D<u>a</u>te Shipped:</b>
<input type="text" name="ds" size="5" maxlength="5" ACCESSKEY="a"
<?php echo "value=\"$now\"" ?> /></p>
</fieldset>
<div>Alt-E:<input type="submit" name="Enter" value="Enter" ACCESSKEY="e" /></div>
</form><!-- End of Form -->
</body>
</html>
I cut out the non-date related code... Anyone's help would be appreciated.
-- Dave
I have an HTML form with a simple date in it. The form inputs the date as m/d in a field named "ds". How do I format the contents of this field so I can store it in a MySQL Date field in my table?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Shipping Notify</title>
<?php
function escape_data ($data) { // Makes data ok for inserting into MySQL tables
global $dbc; // need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
}
$now = date ('n\\\j');
?>
</head>
<body background="back2.jpg">
<?php
define ('DB_USER', '########');
define ('DB_PASS', '################');
define ('DB_HOST', 'localhost');
/* Database Connect */
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASS) or die ('Could not connect to MySQL: ' . mysql_error() );
$db_name = 'my_db';
@mysql_select_db($db_name) or die ('Could not select the database: ' . mysql_error() );
$ds = stripslashes($ds);
/* Store info into my_db:table */
$tbl_name = "table";
/* Prepare data for saving into MySQL */
$ds = escape_data($ds);
/* build the MySQL INSERT query */
$query = "INSERT INTO $tbl_name (date_shipped) VALUES ('$ds')";
$result = @mysql_query($query) or die (' Could not insert record into db: ' . mysql_error() );
?>
<form action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post" name="foo" style="background-image:url('back.jpg')">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>D<u>a</u>te Shipped:</b>
<input type="text" name="ds" size="5" maxlength="5" ACCESSKEY="a"
<?php echo "value=\"$now\"" ?> /></p>
</fieldset>
<div>Alt-E:<input type="submit" name="Enter" value="Enter" ACCESSKEY="e" /></div>
</form><!-- End of Form -->
</body>
</html>
I cut out the non-date related code... Anyone's help would be appreciated.
-- Dave