Jump to content

need some help for my project(php gurus help me out!)


ray_nl

Recommended Posts

im designing a simple car rental page for my project in uni, i done most of the part just need a bit more help about mysql..

 

im trying to do this, if the users puts all the required information in the html form fields and submit it, it will then store the information in a mysql database but im having hard time trying to do this.

 

below is my php and html code..

 

can anyone of you help me out?

thanks in advance

 

this is the html code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<link rel="stylesheet" type="text/css" href="travel.css"/>
    <title>Travel Air Home Page</title>


</head>
</head>

<body> 
 <div align="center">
<div id="header">
</div>


<div id="topnav">
<ul>
<li><a href="Home.html">Home</a></li>
<li><a href="Destinations.html">Destinations</a></li>
<li><a href="Flights.html">Flights</a></li>
<li><a href="car.html">Cars</a></li>
<li><a href="Hotels.html">Hotels</a></li>
<li><a href="Insurance.html">Insurance</a></li>
<li><a href="Build your own.html">Build your own</a></li>
<li><a href="Special Offers.html">Special Offers</a></li>
<li><a href="Reviews.html">Reviews</a></li>
<li><a href="Forum.html">Forum</a></li>
<li><a href="Log.html">Log-In/Register</a></li>

</ul>
</div>

<div id="navigation">

<div id="Welcome">
<H2>Car Reservation</H2>
Welcome to Travel Air. Our aim is to get you the dream holiday you always wanted. We know that booking a perfect holiday is never easy, so 
were designed to give you as many different options as we can. If your only seeking a flight or a hotel or even insurance they can be purchased
seperatly. Alternativly, build your own bundle to save money and get a complete package!


<hr/>
<hr/>
<div id="Why">


<H2>Reserve Online</H2>


        <body>
					   		<FORM METHOD="POST" ACTION="booking_process.php">	


        <div align="center">



        <input type="HIDDEN" name="first_pass" value="no">
        <table>

                           <td colspan="2">Customer Information</td>
                       </tr>
                       <tr>


                           <td>First Name </td><td><input type="text" size="15" name="first_name"" maxlength="40"></td>

                       </tr>
                       <tr>
                           <td>Last Name </td><td><input type="text" size="20" name="last_name" maxlength="40"></td>

                       </tr>
                       <tr>
                           <td>Email </td><td><input type="text" size="20" name="email" maxlength="40"></td>

                       </tr>
                       <tr>
                           <td>Address</td><td><input type="text" size="30" name="address" maxlength="80"></td>

                       </tr>
                       <tr>
                           <td>Contact Number</td><td><input type="text" size="18" name="contact_no" maxlength="20"></td>

                       </tr>
                       <tr>
                           <td colspan="2"> </td>
                       </tr>



        </table>




<hr/>
<hr/>
        <table>
<div id="Why">

                       <tr>
                           <td colspan="2">Vehicle Reservation</td>
                       </tr>
                       <tr>
                           <td>Vehicle Type</td><td>Number of Units</td>
                       </tr>
                       <tr>
                           <td>Car</td><td><select name="units_car">
                                       <option value="0">0
                                       <option value="1">1
                                       <option value="2">2
                                       <option value="3">3
                                       <option value="4">4
                                       <option value="5">5
                                       </select>
                           </td>
                       </tr>
                       <tr>
                           <td>Pickup</td><td><select name="units_pickup">
                                       <option value="0">0
                                       <option value="1">1
                                       <option value="2">2
                                       <option value="3">3
                                       <option value="4">4
                                       <option value="5">5
                                       </select>
                           </td>
                       </tr>
                       <tr>
                           <td>Van</td><td><select name="units_van">
                                       <option value="0">0
                                       <option value="1">1
                                       <option value="2">2
                                       <option value="3">3
                                       <option value="4">4
                                       <option value="5">5
                                       </select>
                           </td>
                       </tr>
                       <tr>
                            <td>Reservation Date</td>
                            <td><select name="month">
                                <option value="jan">January
                                <option value="feb">February
                                <option value="mar">March
                                <option value="apr">April
                                <option value="may">May
                                <option value="jun">June
                                <option value="jul">July
                                <option value="aug">August
                                <option value="sep">September
                                <option value="oct">October
                                <option value="nov">November
                                <option value="dec">December
                                </select>
                            </td>
                            <td>
                                <select name="day">
                                <option value="1">1
                                <option value="2">2
                                <option value="3">3
                                <option value="4">4
                                <option value="5">5
                                <option value="6">6
                                <option value="7">7
                                <option value="8">8
                                <option value="9">9
                                <option value="10">10
                                <option value="11">11
                                <option value="12">12
                                <option value="13">13
                                <option value="14">14
                                <option value="15">15
                                <option value="16">16
                                <option value="17">17
                                <option value="18">18
                                <option value="19">19
                                <option value="20">20
                                <option value="21">21
                                <option value="22">22
                                <option value="23">23
                                <option value="24">24
                                <option value="25">25
                                <option value="26">26
                                <option value="27">27
                                <option value="28">28
                                <option value="29">29
                                <option value="30">30
                                <option value="31">31
                                </select>
                            </td>
                            <td>
                                <select name="year">
                                <option value="2001">2001
                                <option value="2002">2002
                                <option value="2003">2003
                                <option value="2004">2004
                                <option value="2005">2005
                                <option value="2006">2006
                                <option value="2007">2007
                                <option value="2008">2008
                                <option value="2009">2009 
                               </select>
                            </td>
                       </tr>

</div>
        </table>
        <table>
                       <tr>
                            <td>Inquiries/Trip Details </td><td> </td>
                       </tr>
                       <tr>
                            <td colspan="2"><textarea name="inquiries" cols="42" rows="7"></textarea></td>
                       </tr>
                       <tr>
                            <td><input type="submit" value="submit entries"> <input type="reset" value="clear"></td>
                       </tr>
        </table>
        </form>
</div>

<hr/>

<div id="loglink">
<H2>New to Travel Air?</H2>
By registering with Travel Air you gain several benefits. Once registered you can use the forums, leave reviews and start building your dream
holiday. All the information that is required is your name and email address. You can choose to receive free newsletters telling of new deals!
Follow this link to register or if you are a member log in
</div>

</div>
</body
</html>

 

 

 

this is the php code after the user submits the data it will bring to this process page

 

<html>
<head>
<link rel="stylesheet" type="text/css" href="travel.css"/>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Confirm Booking?")
if (answer){
	alert("Booking Confirmed")
	window.location = "Home.html";
}
else{

	window.location = "Car.html";

}
}
//-->
</script>

<title>Reservation Booked</title></head>
<body>
<div align="center">
<div id="header">
</div>


<div id="topnav">
<ul>
<li><a href="Home.html">Home</a></li>
<li><a href="Destinations.html">Destinations</a></li>
<li><a href="Flights.html">Flights</a></li>
<li><a href="car.html">Cars</a></li>
<li><a href="Hotels.html">Hotels</a></li>
<li><a href="Insurance.html">Insurance</a></li>
<li><a href="Build your own.html">Build your own</a></li>
<li><a href="Special Offers.html">Special Offers</a></li>
<li><a href="Reviews.html">Reviews</a></li>
<li><a href="Forum.html">Forum</a></li>
<li><a href="Log.html">Log-In/Register</a></li>

</ul>
</div>

<div id="navigation">
<div id="Welcome">
  
<h1>Your reservation has been booked. We will get back to you soon! Thank you!</h1>

</div>
<hr/>
<hr/>
<div id="Why">
<p><strong>Your First Name:</strong><br />
<?echo "$_POST[first_name]"; ?>
<p><strong>Your Last Name:</strong><br />
<?echo "$_POST[last_name]"; ?>
<p><strong>Your EMail Address:</strong><br />
<?echo "$_POST[email]"; ?>
<p><strong>Your Address:</strong><br />
<?echo "$_POST[address]"; ?>
<p><strong>Your Contact No:</strong><br />
<?echo "$_POST[contact_no]"; ?>
<p><strong>Cars:</strong><br />
<?echo "$_POST[units_car]"; ?>
<p><strong>Pickups:</strong><br />
<?echo "$_POST[units_pickup]"; ?>
<p><strong>Vans:</strong><br />
<?echo "$_POST[units_van]"; ?>
<p><strong>Reservation Date:</strong><br />
<?echo "$_POST[month]"; ?><br />
<?echo "$_POST[day]"; ?><br />
<?echo "$_POST[year]"; ?><br />
<p><strong>Message:</strong><br />
<?echo "$_POST[inquiries]"; ?><br /></p>

<hr/>
<input type="button" onclick="confirmation()" value="Confirm Booking">

</body>
</html>

Link to comment
Share on other sites

sorry im kinda new to this.. where do i insert that?

 

"INSERT INTO `table_name` (`field1`, `field2`) VALUES('field1 data', 'field2 data')"

 

will that send all the required information such as the "First Name", "Last Name", "Reservation Date" ect ect?

 

where do i put that code? also  shouldnt there be another code to connect to the mysql?

thanks!

Link to comment
Share on other sites

include 'connection string'

$sql="INSERT INTO `table_name` (`firstname`, `lastname`) VALUES('$_post['first_name']', '$_POST['last_name']')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

<p><strong>Your First Name:</strong><br />
<?echo "$_POST[first_name]"; ?>
<p><strong>Your Last Name:</strong><br />
<?echo "$_POST[last_name]"; ?>
<p><strong>Your EMail Address:</strong><br />
<?echo "$_POST[email]"; ?>
<p><strong>Your Address:</strong><br />
<?echo "$_POST[address]"; ?>
<p><strong>Your Contact No:</strong><br />
<?echo "$_POST[contact_no]"; ?>
<p><strong>Cars:</strong><br />
<?echo "$_POST[units_car]"; ?>
<p><strong>Pickups:</strong><br />
<?echo "$_POST[units_pickup]"; ?>
<p><strong>Vans:</strong><br />
<?echo "$_POST[units_van]"; ?>
<p><strong>Reservation Date:</strong><br />
<?echo "$_POST[month]"; ?><br />
<?echo "$_POST[day]"; ?><br />
<?echo "$_POST[year]"; ?><br />
<p><strong>Message:</strong><br />
<?echo "$_POST[inquiries]"; ?><br /></p>


mysql_close($con);

I would advise not just coping this into your page before you atleast read first two things posted below

 

http://www.w3schools.com/php/php_mysql_intro.asp

http://us3.php.net/mysql_real_escape_string

two things you need to read before you put it on a page.

 

Link to comment
Share on other sites

include 'connection string'

$sql="INSERT INTO `table_name` (`firstname`, `lastname`) VALUES('$_post['first_name']', '$_POST['last_name']')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

<p><strong>Your First Name:</strong><br />
<?echo "$_POST[first_name]"; ?>
<p><strong>Your Last Name:</strong><br />
<?echo "$_POST[last_name]"; ?>
<p><strong>Your EMail Address:</strong><br />
<?echo "$_POST[email]"; ?>
<p><strong>Your Address:</strong><br />
<?echo "$_POST[address]"; ?>
<p><strong>Your Contact No:</strong><br />
<?echo "$_POST[contact_no]"; ?>
<p><strong>Cars:</strong><br />
<?echo "$_POST[units_car]"; ?>
<p><strong>Pickups:</strong><br />
<?echo "$_POST[units_pickup]"; ?>
<p><strong>Vans:</strong><br />
<?echo "$_POST[units_van]"; ?>
<p><strong>Reservation Date:</strong><br />
<?echo "$_POST[month]"; ?><br />
<?echo "$_POST[day]"; ?><br />
<?echo "$_POST[year]"; ?><br />
<p><strong>Message:</strong><br />
<?echo "$_POST[inquiries]"; ?><br /></p>


mysql_close($con);

I would advise not just coping this into your page before you atleast read first two things posted below

 

http://www.w3schools.com/php/php_mysql_intro.asp

http://us3.php.net/mysql_real_escape_string

two things you need to read before you put it on a page.

 

thank you so much! i did read and it does help :D

Link to comment
Share on other sites

one last help..

 

you know that when my form page goes to the next process page i added a confirm booking button when the user presses the confirm button it will alert "confirmed" thats all. is there a way to add a code so that when the user presses "confirm" it will send me a email containing all his details?

 

here is the javascript code:

 

<!--
function confirmation() {
var answer = confirm("Confirm Booking?")
if (answer){
	alert("Booking Confirmed")
	window.location = "Home.html";
}
else{

	window.location = "Car.html";

}
}

Link to comment
Share on other sites

you could but the way its coded the confirm script doesn't really do anything except take you to another page (the data was already stored)

also javascript can't send emails, so a simpler solution would be to send the mail when the data was stored and add the confirm to the submit button then have a redirect from the PHP

 

1. put the confirm script on the "Travel Air Home Page" page and add onclick="confirmation();" to the submit button.

1.1 change <FORM METHOD="POST" ACTION="booking_process.php">  to <FORM METHOD="POST" ACTION="booking_process.php" name="booking" > 

1.2 change window.location = "Home.html"; to  document.booking.submit();

(now you form will need to be confirmed before its processed)

 

2. edit booking_process.php to send email and goto home.html

2.1 after mysql_close($con); add mail("bookees@mail.com", "New booking", $_POST['first_name']."has booked blar");

2.2 after 2.1 add header("Location: home.html");

2.3 the problem: 2.2 will NOT work as you have output to the page and if it did work you won't see it as your being redirected.. so you need to remove it.. call page should be like this

include 'connection string'

$sql="INSERT INTO `table_name` (`firstname`, `lastname`) VALUES('$_post['first_name']', '$_POST['last_name']')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
mysql_close($con);
mail("bookees@mail.com", "New booking", $_POST['first_name']."has booked blar");
header("Location: home.html");

 

Hope that helps

Link to comment
Share on other sites

now i keep getting a form validation error :-[

 

i attached a picture it says "could not get form object myform"

 

here is the form validation code:

<script language="JavaScript" type="text/javascript">
		var frmvalidator = new Validator("myform");
		frmvalidator.addValidation("first_name","req","Please enter your First Name");
		frmvalidator.addValidation("first_name","maxlen=20",
	"Max length for FirstName is 20");
		frmvalidator.addValidation("first_name","alpha");

		frmvalidator.addValidation("last_name","req","Please enter your Last Name");
		frmvalidator.addValidation("last_name","maxlen=20");

		frmvalidator.addValidation("email","maxlen=50");
		frmvalidator.addValidation("email","req","Please enter your Email");
		frmvalidator.addValidation("email","email");

		frmvalidator.addValidation("address","maxlen=50");
		frmvalidator.addValidation("address","req","Please enter your Address");


		frmvalidator.addValidation("contact_no","maxlen=50");
		frmvalidator.addValidation("contact_no","req","Please enter your Contact Number");
		frmvalidator.addValidation("contact_no","num");

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

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.