Hello, I am using php to create a form. I would like that forms
information to go into a database. When creating tables where the
information that i entered into the form will be stored, where exactly
do i place the code for creating the tables. Do I have to create a new
php file? and how do i link the information from the form to the
tables. Please go easy on me I am brand new to PHP and SQL. here is
the code that i have so far for the form if this helps any. Thank you
for any help that you can provide.
//////
<html>
<title>Service Station</title>
</head>
<!--checks to see if all field are entered-->
<SCRIPT language="JavaScript">
<!--
function validateSelect(){
var errors="";
var form = document.customer;
var first = form.first;
if(first.value==""){
errors+="\nYou must enter a first name.";
}
var last = form.last;
if(last.value==""){
errors+="\nYou must enter a last name.";
}
var add=form.add;
if(add.value==""){
errors+="\nYou must enter an address.";
}
var city=form.city;
if(city.value==""){
errors+="\nYou must enter a city name.";
}
var province=form.province;
if(province.value==""){
errors+="\nYou must enter a province name.";
}
var phone=form.phone;
if(phone.value==""){
errors+="\nYou must enter the phone number's area code.";
}
var phone2=form.phone2;
if(phone2.value==""){
errors+="\nYou must enter the phone number's next three
digits.";
}
var phone3=form.phone3;
if(phone3.value==""){
errors+="\nYou must enter the phone number's last four
digits.";
}
var make=form.make;
if(make.value==""){
errors+="\nYou must enter the make of the vehicle.";
}
var model=form.model;
if(model.value==""){
errors+="\nYou must enter the model of the vehicle.";
}
var year=form.year;
if(year.value==""){
errors+="\nYou must enter the year of the vehicle.";
}
var color=form.color;
if(color.value==""){
errors+="\nYou must enter the color of the vehicle.";
}
var cost=form.cost;
if(cost.value==""){
errors+="\nYou must enter the cost.";
}
var towing=form.towing;
if(towing.value==""){
errors+="\nYou must enter towing cost.";
}
var subcontract=form.subcontract;
if(subcontract.value==""){
errors+="\nYou must enter subcontract.";
}
var environmental=form.environmental;
if(environmental.value==""){
errors+="\nYou must enter the environmental.";
}
var date=form.date;
if(date.value==""){
errors+="\nYou must enter the date of service.";
}
var time=form.time;
if(time.value==""){
errors+="\nYou must enter the time of service.";
}
var lname=form.lname;
if(lname.value==""){
errors+="\nYou must enter the first name of the laborer.";
}
var lname2=form.lname2;
if(lname2.value==""){
errors+="\nYou must enter the last name of the laborer.";
}
if (errors) {
alert("The form was not submitted due to the following
error(s):\n"+errors+"\n\nPlease make changes and submit the form
again.");
}
document.MM_returnValue = (errors == "");
}
function TotalCost(field){
var c=eval(document.customer.cost.value);
var t=eval(document.customer.towing.value);
var s=eval(document.customer.subcontract.value);
var e=eval(document.customer.environmental.value);
var tax=document.customer.taxes.value=(c+t+s+e)*0.15;
var total=document.customer.total.value=(c+t+s+e)+tax;
document.customer.taxes.value=Math.round(tax*100)/100;
document.customer.total.value=Math.round(total*100 )/100;
}
//-->
</SCRIPT>
<body BGCOLOR=GRAY>
<?
//the current date
print " <b> ".date("F d, Y")." <br>
<br>
";
?>
<?=$errormessage?>
<br>
<!--<form action="?=$_SERVER['PHP_SELF']?>
http://localhost/meaneyPHP/output.php" method="post">
//-->
<!--<form name="customer" "action="?=$_SERVER['PHP_SELF']?>"
method="post" onSubmit="validateSelect();return
document.MM_returnValue">
//-->
<form name="customer" action="CustomerInfo.php" method="post"
onSubmit="validateSelect();return document.MM_returnValue">
<table border="0" cellpadding="0" cellspacing="0">
<tr><td>First Name:</td><td><input type="text" name="first"
value="<?$first =$_POST['first']?>">
Last Name:<input type="text" name="last"
value="<?$last=$_POST['last']?>">
</td></tr>
<tr><td>Address:</td><td><input type="text" name="add" size=50
value="<?$add=$_POST['add']?>"></td></tr>
<tr><td>City:</td><td><input type="text" name="city" size=20
value="<?$city=$_POST['city']?>">
Province:<input type="text" name="province" size=3 maxlength=2
value="<?$province=$_POST['province']?>"></td></tr>
<tr><td>Phone Number:</td><td><input type="integer" name="phone"
size=3 maxlength=3 value="<?$phone=$_POST['phone']?>">
<input type="integer" name="phone2" size=3 maxlength=3
value="<?$phone2=$_POST['phone2']?>">
<input type="integer" name="phone3" size=4 maxlength=4
value="<?$phone3=$_POST['phone3']?>"></td></tr>
<tr><td>Vehicle Make:</td><td><input type="text" name="make"
value="<?$make=$_POST['make']?>"></td></tr>
<tr><td>Vehicle Model:</td><td><input type="text" name="model"
value="<?$model=$_POST['model']?>"></td></tr>
<tr><td>Vehicle Year:</td><td><input type="text" name="year"
value="<?$year=$_POST['year']?>"></td></tr>
<tr><td>Vehicle Color:</td><td><input type="text" name="color"
value="<?$color=$_POST['color']?>"></td></tr>
<tr><td>Cost:</td><td><input type="text" name="cost" size=10 value="0"
onBlur="TotalCost(this);" value="<?$cost=$_POST['cost']?>">
<tr><td>Towing:</td><td><input type="text" name="towing" size=10
value="0" onBlur="TotalCost(this);"
value="<?$towing=$_POST['towing']?>">
<tr><td>Subcontract:</td><td><input type="text" name="subcontract"
size=10 value="0" onBlur="TotalCost(this);"
value="<?$subcontract=$_POST['subcontract']?>">
<tr><td>Environmental:</td><td><input type="text" name="environmental"
size=10 value="0" onBlur="TotalCost(this);"
value="<?$enviromental=$_POST['environmental']?>">
<tr><td>Taxes:</td><td><input type="text" name="taxes" size=10
value="0" onBlur="TotalCost(this);"
value="<?$taxes=$_POST['taxes']?>">
<tr><td>Date Serviced:</td><td><input type="text" name="date"
value="<?$date=$_POST['date']?>">
Time:<input type="text" name="time" size=7
value="<?$time=$_POST['time']?>"></td></tr>
<tr><td>Labour by: <i>first</i></td><td><input type="text"
name="lname" value="<?$lname =$_POST['lname']?>">
<i>last</i><input type="text" name="lname2"
value="<?$lname2=$_POST['lname2']?>">
</td></tr>
<tr><td>Total Cost:</td><td><input type="text" name="total" size=10
value="<?$total=$_POST['total']?>"><i>Taxes Included</i>
<?php
//Type of payment
$p_effort=$_POST['effort'];
?>
<tr><td>Payment by:</tr></td>
<tr><td><input type=radio name='effort' value=Cash checked<?php
if($p_effort==Cash) echo "checked"; ?>>Cash</tr></td>
<tr><td><input type=radio name='effort' value=Visa <?php
if($p_effort==Visa) echo "checked"; ?>>Visa
<tr><td><input type=radio name='effort' value=MasterCard<?php
if($p_effort==MasterCard) echo "checked"; ?>>Master Card</tr></td>
<tr><td><input type=radio name='effort' value=AMEX<?php
if($p_effort==AMEX) echo "checked"; ?>>AMEX</tr></td>
<!--Submit the form -->
<tr><td> <input type="SUBMIT" value="Submit"></B></tr></td>
<br><br>
<?php
if ($_POST['submit']) {
}
?>
<tr><td><a href= "Search.php" >SEARCH</a><br></tr></td>
</body>
</html>