Jump to content

Wondering if this page will work?


rthomson

Recommended Posts

Hi, I have a form that I am trying to get working.  The page is named "reserv_test.php".  Not sure if I am trying to do to much, but can anyone tell me if this will work?  If so, what do I need to do to make it work?

 

Here is the code...

<html>
<head>
<title>Booking Form</title>

<script type="text/javascript">
function showMonth(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
   }
  }
xmlhttp.open("GET","reserv_test.php?q="+str,true);
xmlhttp.send();
}
</script>

</head>
<body>
<div>
<p align="left"><font face="arial" size="4"><u>Booking Form</u></font></p>  
      <form method="post" action="resersend.php">
<p><font face="arial" size="2" color="#336600">Reservation month:</font>
<select name="months" onChange="showMonth(this.value)">
<option value="" selected="selected">Choose One</option>
<option value="May 2011">May 2011</option>
<option value="June 2011">June 2011</option>
<option value="July 2011">July 2011</option>
<option value="August 2011">August 2011</option>
<option value="September 2011">September 2011</option>
<option value="October 2011">October 2011</option>
<option value="November 2011">November 2011</option>
<option value="December 2011">December 2011</option>
<option value="January 2012">January 2012</option>
<option value="February 2012">February 2012</option>
<option value="March 2012">March 2012</option>
<option value="April 2012">April 2012</option>
</select>
</form></p><br />

<?php

$q=$_GET["q"];

$con = mysql_connect('my_host', 'my_user', 'my_pwd');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$sql="SELECT *
      FROM daterange
  WHERE DEND > DATE(NOW())
  AND STATUS='A' AND MONTH = '".$q."'
      ORDER BY RID, DATE, SITE";

$result = mysql_query($sql);


// Determine the number of reservation dates
$number = mysql_numrows($result);


// Create drop-down menu of reservation dates
print "<font size=\"3\" face=\"Arial\"><b>Select Your Reservation:</b><br>
<form action=\"resersend.php\" method=\"post\">
<select name=\"RID\">
    <option value=\"\">Choose One</option>";

for ($i=0; $i<$number; $i++) {
     $RID = mysql_result($result,$i,"RID");
     $DATE = mysql_result($result,$i,"DATE");
     $SITE = mysql_result($result,$i, "SITE");
 $PRICE = mysql_result($result,$i, "PRICE");
     print "<option value=\"$RID\">$DATE, $SITE, $PRICE</option>";
}

print "</select><p align=left><label><font size=\"3\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br>";

print "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br>";

print "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br>";

print "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br>";

print "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br>";

print "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br>";

print "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br>";

print "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\"";
print "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\"";
print "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br>";

print "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br>";

 

Any help would be appreciated.  Thanks.

Link to comment
Share on other sites

Sorry, I guess it would help to say what I am trying to do.  When you choose a month it is supposed to populate the reservations select box.  Then they would fill the remainder of the form and then it would post to reversend.php upon submit.  I had it working separately, but it would not post in any browser except Firefox 3.6.  I guess wc3 does not allow form inside form anymore....

Link to comment
Share on other sites

Sorry, I guess it would help to say what I am trying to do.  When you choose a month it is supposed to populate the reservations select box.  Then they would fill the remainder of the form and then it would post to reversend.php upon submit.  I had it working separately, but it would not post in any browser except Firefox 3.6.  I guess wc3 does not allow form inside form anymore....

 

You should look at http://jquery.com/ it makes this so so easy, but if you wanna do it like this, you will have to

 

from reserv_test.php do something like this code:

 

<?php
  // connect to db
  $reservations = array();
  $q = mysql_query("SELECT r_id FROM reservations WHERE r_taken = '0' AND r_month = '{$_POST['month']}'");
  while ($x = mysql_fetch_assoc($q)) {
    $reservations[] = $x;
  }
  echo json_encode($reservations);
?>

 

and in the js

 

you will get your response from the server, if you're using jQuery it will already process the JSON from the response, however, if you're using str8 ajax in javascript, you'll need to execute your response

 

var reservations = eval('('+xmlHttpRequest.responseText+')');

 

and there you go, reservations will hold an object of all available reservations! :)

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.