i am having trouble with the below code, what this pages does is it inserts data that a user inputs in a feild to a mysql database. Problem is when i click submit i get an error that says "document.data.date is null or not an object" i do not understand this!!!!. HELP!!!. what it does is insert the date automatically into the date field.
OR what i want to do is this. i was the data entered in the feilds sent to a php script that will display all the data entered then when a confirm button is pressed it inserts data into database. how do i transfer the variables???? help there too!!.
OR how to i direct someone to a page when they click sumbit in the script below to a page, cos at the moment all that happens is that a message is displayed.
PLEASE help me acheive the above
the below page in acton can be found at:
http://www.xbyte.co.uk/form.php
PLEASE e-mail me at nikhil@xbyte.co.uk
<head>
<title>Test to validate/input data into database</title>
</head>
<body>
<script language="javascript">
<!--
function validateForm ( )
{
valid = true;
if ( document.data.first.value == "" )
{
alert ( "Please fill in your name." );
valid = false;
}
if ( document.data.age.value == "" )
{
alert ( "Please fill in your age." );
valid = false;
}
return valid;
}
//-->
</script>
<?php
if ($submit) {
// process form
$db = mysql_connect("host", "ussername", "password");
mysql_select_db("omega",$db);
$sql = "INSERT INTO data (first,age,date) VALUES ('$first','$age','$date')";
$result = mysql_query($sql);
echo "Thank you! Information entered./n";
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>" name = "data">
First name:<input type="Text" name="first"><br>
Age:<input type="Text" name="age"><br>
Date:<input type="Text" name="date" value =""><br>
<input type="Submit" name="submit" value="Enter information" OnClick = "return validateForm()">
</form>
<?php
} // end if
?>
<script language = "javascript">
/Current date in form credit:
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
/
var mydate=new Date()
var theyear=mydate.getYear()
if (theyear < 1000)
theyear+=1900
var theday=mydate.getDay()
var themonth=mydate.getMonth()+1
if (themonth<10)
themonth="0"+themonth
var theday=mydate.getDate()
if (theday<10)
theday="0"+theday
//////EDIT below three variable to customize the format of the date/////
var displayfirst=theyear
var displaysecond=themonth
var displaythird=theday
////////////////////////////////////
var cheese = document.data.date.value=displayfirst+"-"+displaysecond+"-"+displaythird
document.data.date.value = cheese
</script>
</body>