I have a short and rather untidy script I've been working on. It is designed to fetch a customer from the database and the customers pets. The user then selects the dates and the pets to book for a stay in the kennels and the form gets posted to the next page where the booking is entered into the database.
At the moment it does one booking for one pet... but what I want it to do is repeat the booking for each pet selected using the the same data.
<?
if ($_POST['postcode'] != "") {
$link = mysqli_connect('localhost','******','***********8','******');
$PC = $_POST['postcode'] ;
$telno= $_POST['telno'];
$telno = trim($telno);
$PC = trim($PC);
$nononchar = array(" ", "(", ")", "[", "]", "-", ".", ",", "#") ;
$telno = str_replace($nononchar, "", $telno);
$PC = str_replace($nononchar, "", $PC);
$select = "SELECT CustomerID, ContactFirstName, ContactLastName FROM Clients where PostalCode='$PC' && PhoneNumber= '$telno' ";
$result = mysqli_query($link, $select);
while ($row = mysqli_fetch_array($result)) {
$fn = $row['ContactFirstName'];
$ln = $row['ContactLastName'];
$custid = $row['CustomerID'];
setcookie('user_id', $fn, time()+(60*60*24*365));
?>
<? echo "$fn" ?> <? echo "$ln" ?> . Your ID is <? echo $custid ?> and your pets are listed below: </br>
<?
}
?> </BR> <?
$direct = 'requestbooking.php';
}else{
echo "It's a blank!";
$direct = 'sendcode.html';
}
?>
<script language="JavaScript" src="pupdate.js">
/*
Popup calendar script by Sev Kotchnev (webmaster@personal-connections.com)
For full source code and installation instructions to this script
Visit http://www.dynamicdrive.com
*/
</script>
<html><body>
<FORM METHOD="POST" ACTION="<? echo $direct ?>" name="myform">
<P>Your ID <INPUT TYPE="text" NAME="CustomerID"
VALUE="<? echo $custid ?>"/> </BR>
Name
<INPUT TYPE="text" NAME="fn"
VALUE="<? echo $fn ?>"/>
<INPUT TYPE="text" NAME="ln"
VALUE="<? echo $ln ?>" /></BR>
From:<INPUT TYPE="text" NAME="from"/> <a href="#" onClick="getCalendarFor(document.myform.from);return false">[Choose one]</a>
To:<INPUT TYPE ="text" NAME="to"/> <a href="#" onClick="getCalendarFor(document.myform.to);return false">[Choose one]</a> </BR>
You must use the date format YYYY-MM-DD
<SELECT multiple="yes" NAME="SelectPet">
<? $select = "SELECT ProjectID, BoardersName, Boardertype FROM ClientsPets where CustomerID='$custid'";
$result = mysqli_query($link, $select);
while ($row1 = mysqli_fetch_array($result)) {
$PID = $row1['ProjectID'];
$pn = $row1['BoardersName'];
$pt = $row1['Boardertype'];
echo "<OPTION VALUE=$PID> $pn the $pt </OPTION>";
} ?>
</SELECT>
<P>Do you plan to collect your pet in the morning or afternoon?
<SELECT NAME="AMPM">
<OPTION VALUE=AM> Morning </OPTION>
<OPTION VALUE=PM> Afternoon </OPTION>
</SELECT>
</P>
<P><INPUT TYPE ="SUBMIT" VALUE="Send" />
</FORM>
<a href="sendcode.html"> Try Again </a>
<script language="JavaScript">
if (document.all) {
document.writeln("<div id=\"PopUpCalendar\" style=\"position:absolute; left:0px; top:0px; z-index:7; width:200px; height:77px; overflow: visible; visibility: hidden; background-color: #FFFFFF; border: 1px none #000000\" onMouseOver=\"if(ppcTI){clearTimeout(ppcTI);ppcTI=false;}\" onMouseOut=\"ppcTI=setTimeout(\'hideCalendar()\',500)\">");
document.writeln("<div id=\"monthSelector\" style=\"position:absolute; left:0px; top:0px; z-index:9; width:181px; height:27px; overflow: visible; visibility:inherit\">");}
else if (document.layers) {
document.writeln("<layer id=\"PopUpCalendar\" pagex=\"0\" pagey=\"0\" width=\"200\" height=\"200\" z-index=\"100\" visibility=\"hide\" bgcolor=\"#FFFFFF\" onMouseOver=\"if(ppcTI){clearTimeout(ppcTI);ppcTI=false;}\" onMouseOut=\"ppcTI=setTimeout('hideCalendar()',500)\">");
document.writeln("<layer id=\"monthSelector\" left=\"0\" top=\"0\" width=\"181\" height=\"27\" z-index=\"9\" visibility=\"inherit\">");}
else {
document.writeln("<p><font color=\"#FF0000\"><b>Error ! The current browser is either too old or too modern (usind DOM document structure).</b></font></p>");}
</script>
<noscript><p><font color="#FF0000"><b>JavaScript is not activated !</b></font></p></noscript>
<table border="1" cellspacing="1" cellpadding="2" width="200" bordercolorlight="#000000" bordercolordark="#000000" vspace="0" hspace="0"><form name="ppcMonthList"><tr><td align="center" bgcolor="#CCCCCC"><a href="javascript:moveMonth('Back')" onMouseOver="window.status=' ';return true;"><font face="Arial, Helvetica, sans-serif" size="2" color="#000000"><b>< </b></font></a><font face="MS Sans Serif, sans-serif" size="1">
<select name="sItem" onMouseOut="if(ppcIE){window.event.cancelBubble = true;}" onChange="switchMonth(this.options[this.selectedIndex].value)" style="font-family: 'MS Sans Serif', sans-serif; font-size: 9pt"><option value="0" selected>2000 • January</option><option value="1">2000 • February</option><option value="2">2000 • March</option><option value="3">2000 • April</option><option value="4">2000 • May</option><option value="5">2000 • June</option><option value="6">2000 • July</option><option value="7">2000 • August</option><option value="8">2000 • September</option><option value="9">2000 • October</option><option value="10">2000 • November</option><option value="11">2000 • December</option><option value="0">2001 • January</option></select></font><a href="javascript:moveMonth('Forward')" onMouseOver="window.status=' ';return true;"><font face="Arial, Helvetica, sans-serif" size="2" color="#000000"><b> ></b></font></a></td></tr></form></table>
<table border="1" cellspacing="1" cellpadding="2" bordercolorlight="#000000" bordercolordark="#000000" width="200" vspace="0" hspace="0"><tr align="center" bgcolor="#CCCCCC"><td width="20" bgcolor="#FFFFCC"><b><font face="MS Sans Serif, sans-serif" size="1">Su</font></b></td><td width="20"><b><font face="MS Sans Serif, sans-serif" size="1">Mo</font></b></td><td width="20"><b><font face="MS Sans Serif, sans-serif" size="1">Tu</font></b></td><td width="20"><b><font face="MS Sans Serif, sans-serif" size="1">We</font></b></td><td width="20"><b><font face="MS Sans Serif, sans-serif" size="1">Th</font></b></td><td width="20"><b><font face="MS Sans Serif, sans-serif" size="1">Fr</font></b></td><td width="20" bgcolor="#FFFFCC"><b><font face="MS Sans Serif, sans-serif" size="1">Sa</font></b></td></tr></table>
<script language="JavaScript">
if (document.all) {
document.writeln("</div>");
document.writeln("<div id=\"monthDays\" style=\"position:absolute; left:0px; top:52px; z-index:8; width:200px; height:17px; overflow: visible; visibility:inherit; background-color: #FFFFFF; border: 1px none #000000\"> </div></div>");}
else if (document.layers) {
document.writeln("</layer>");
document.writeln("<layer id=\"monthDays\" left=\"0\" top=\"52\" width=\"200\" height=\"17\" z-index=\"8\" bgcolor=\"#FFFFFF\" visibility=\"inherit\"> </layer></layer>");}
else {/*NOP*/}
</script>
</body></html>
POST TO
<html><body>
<?
$link = mysqli_connect('localhost','******','p******e','w*****e');
$ProjectID = $_POST['SelectPet'];
$fn = $_POST['fn'];
$ln = $_POST['ln'];
$from = $_POST['from'];
$to = $_POST['to'];
$CustomerID = $_POST['CustomerID'];
$AMPM = $_POST['AMPM'];
$date1 = "$from";
$date2 = "$to";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$totaldays = ($diff / 60 / 60 / 24);
$thanks = "Thankyou $fn. </BR>You have booked for ";
$insert = "INSERT INTO Bookings
(CustomerID, DateFrom, DateTo, ProjectID, AMPM )
VALUES ('$CustomerID',(STR_TO_DATE('$from', '%m/%d/%Y')), (STR_TO_DATE('$to', '%m/%d/%Y')), '$ProjectID', '$AMPM')";
// execute and check
if (!mysqli_query($link, $insert)) {
$msg = "ERROR";
} else {
$msg = " Record added";
}
echo $thanks;
printf("%d years, %d months, %d days\n", $years, $months, $days);
$rate = 18;
$bill = ($rate*$totaldays);
echo ". </BR>The charge for $totaldays nights is £$bill. </BR>";
If ($AMPM == "AM") {
$totalbill = $bill;
} else {
$totalbill = ($bill+$rate);}
If ($AMPM == "AM") {
$supmsg = " " ;
} else {
$supmsg = "As you have requested to pick your pet up in the afternoon there is a supplementary charge of an extra day at £$rate bringing your total bill to £$totalbill. </BR> " ;}
echo $supmsg;
echo $msg;
echo " </BR> We hope your pet enjoys the stay";
?>
</br>
<a href="sendcode.php"> Click here to start again </a>
</body>
</html>
I'm a real php beginner so please go slowly - any help appreciated!