0

Hi guys i have an assignment and it's asking me to let the user enter data into one of three text boxes to search for something in a database it also has to show the results in a table and be hyperlinked to the next page being bookingdetail.php and the page has to submit to itself. i have started although i cannot figure out what is wrong with my code. here it is:

<?xml version="1.0" encoding="UTF-8"?>
<!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" lang="en">

<head>
	<title>Aus AutoService - Find a Booking</title>
</head>
<body>
<?php
if(isset($_post["submit"])){
$familyname = $_POST('fName');
$phonenumber = $_POST('phNum');
$regno = $_POST('regNum');
$conn=mysql_connect("localhost","twastudent","prac3") or die(mysql_error());
mysql_select_db(autoservice, $conn) or die(mysql_error());
if(strlen($familyname) > 0 ){
$result1 = mysql_query("SELECT familyName, firstName, suburb, contact, rego, bookingDate FROM 
customer, customerCar, booking WHERE familyName='$familyname' ORDER BY familyName, bookingDate");
}
else if(strlen($phonenumber) > 0 ){
$result2 = mysql_query("SELECT familyName, firstName, suburb, contact, rego, bookingDate FROM 
customer, customerCar, booking WHERE contact='$phonenumber' ORDER BY familyName, bookingDate");
}
else if(strlen($regno) > 0 ){
$result3 = mysql_query("SELECT familyName, firstName, suburb, contact, rego, bookingDate FROM 
customer, customerCar, booking WHERE booking.rego='$regno' ORDER BY familyName, bookingDate");
}
}



?>
<form id="findBooking" method="post" action="findbooking.php">
<p>Please enter the appropriate data into one of the three fields below:</p>
<table border="0">
<tr>
<td>Family Name</td>
<td>Phone Number</td>
<td>Vehicle Registration Number</td>
</tr>
<tr>
<td><input type="text" name="fName"/></td>
<td><input type="text" name="phNum"/></td>
<td><input type="text" name="regNum"/></td>
</tr>
</table>
<table>
<?php
while ($row = mysql_fetch_array($result1) { ?>
<tr>
<td><a href="BookingDetail.php=?familyname<?php echo $row["firstName"]?>"/></td>
<td><a href="BookingDetail.php=?familyname<?php echo $row["familyName"]?>"/></td>
<td><a href="BookingDetail.php=?familyname<?php echo $row["suburb"]?>"/></td>
<td><a href="BookingDetail.php=?familyname<?php echo $row["contact"]?>"/></td>
<td><a href="BookingDetail.php=?familyname<?php echo $row["rego"]?>"/></td>
<td><a href="BookingDetail.php=?familyname<?php echo $row["bookingDate"]?>"/></td>
</tr>
<?php }
mysql_close($conn); ?>

<?php
while ($row = mysql_fetch_array($result2) { ?>
<tr>
<td><a href="BookingDetail.php=?phonenumber<?php echo $row["firstName"]?>"/></td>
<td><a href="BookingDetail.php=?phonenumber<?php echo $row["familyName"]?>"/></td>
<td><a href="BookingDetail.php=?phonenumber<?php echo $row["suburb"]?>"/></td>
<td><a href="BookingDetail.php=?phonenumber<?php echo $row["contact"]?>"/></td>
<td><a href="BookingDetail.php=?phonenumber<?php echo $row["rego"]?>"/></td>
<td><a href="BookingDetail.php=?phonenumber<?php echo $row["bookingDate"]?>"/></td>
</tr>
<?php }
mysql_close($conn); ?>

<?php
while ($row = mysql_fetch_array($result3) { ?>
<tr>
<td><a href="BookingDetail.php=?regno<?php echo $row["firstName"]?>"/></td>
<td><a href="BookingDetail.php=?regno<?php echo $row["familyName"]?>"/></td>
<td><a href="BookingDetail.php=?regno<?php echo $row["suburb"]?>"/></td>
<td><a href="BookingDetail.php=?regno<?php echo $row["contact"]?>"/></td>
<td><a href="BookingDetail.php=?regno<?php echo $row["rego"]?>"/></td>
<td><a href="BookingDetail.php=?regno<?php echo $row["bookingDate"]?>"/></td>
</tr>
<?php }
mysql_close($conn); ?>

<input type="submit" value="log in" name="submit"/>
<input type="reset" />
</form>
</body>
</html>
2
Contributors
10
Replies
16
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

1) You should not use there queries. Integrate there inputs in one query using OR operator. (you may also give one more dropdown with three text boxes that is AND, OR)

2) Same way to display you should not use three loops, just one is enough

3) for going to details page, You should use primary key of your view, Here I think its regno

0

Hi sorry could you please explain further showing an example perhaps because at the moment my page doesn't load.

0

post your table structure script with data, that are used in above page

Edited by urtrivedi: n/a

0

first remove first xml definition line
Then test below code in your environment.
also change join condition for customer, customerCar, booking in first $filter variable. otherwise you will get duplicated rows or error in result.

<!--?xml version="1.0" encoding="UTF-8"?-->
<!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" lang="en">

<head>
	<title>Aus AutoService - Find a Booking</title>
</head>
<body>
<?php
if(isset($_post["submit"]))
{
$familyname = $_POST('fName');
$phonenumber = $_POST('phNum');
$regno = $_POST('regNum');
$conn=mysql_connect("localhost","twastudent","prac3") or die(mysql_error());
mysql_select_db(autoservice, $conn) or die(mysql_error());

$filter=" where customer.custid=customercar.custid and customercar.regno=booking.regno ";

if(strlen($familyname) > 0 )
    $filter.=" and familyName='$familyname' ";
else if(strlen($phonenumber) > 0 )
    $filter = " and contact='$phonenumber' ";
else if(strlen($regno) > 0 )
    $filter = " and booking.rego='$regno' ";



$result1 = mysql_query("SELECT familyName, firstName, suburb, contact, rego, bookingDate FROM 
customer, customerCar, booking ($filter ) ORDER BY familyName, bookingDate");


}



?>
<form id="findBooking" method="post" action="findbooking.php">
<p>Please enter the appropriate data into one of the three fields below:</p>
<table border="0">
<tr>
<td>Family Name</td>
<td>Phone Number</td>
<td>Vehicle Registration Number</td>
</tr>
<tr>
<td><input type="text" name="fName"/></td>
<td><input type="text" name="phNum"/></td>
<td><input type="text" name="regNum"/></td>
</tr>
</table>
<table>
<?php
while ($row = mysql_fetch_array($result1)) { ?> 
<tr>
<td><?php echo $row["firstName"]?></td>
<td><?php echo $row["familyName"]?></td>
<td><?php echo $row["suburb"]?>td>
<td><?php echo $row["contact"]?></td>
<td><a href="BookingDetail.php=?regno=<?php echo $row["rego"]?>"><?php echo $row["rego"]?> </a></td>
<td><?php echo $row["bookingDate"]?></td>
</tr>
<?php }
mysql_close($conn); ?>


<input type="submit" value="log in" name="submit"/>
<input type="reset" />
</form>
</body>
</html>

Edited by urtrivedi: n/a

0

I have added .= operator, make that change above

if(strlen($familyname) > 0 )
    $filter.=" and familyName='$familyname' ";
else if(strlen($phonenumber) > 0 )
    $filter .= " and contact='$phonenumber' ";
else if(strlen($regno) > 0 )
    $filter .= " and booking.rego='$regno' ";
0

kk now i get a weird error which i have sent to you. and i am not sure why.

0

I told you, that you need to change following line according to your table design. I do not know how your tables are related to each other.

$filter=" where customer.custid=customercar.custid and customercar.regno=booking.regno "

Also post sql file of 3 tables only (used above customer, customerCar, booking ).
Do not send whole database structure here in text format. I need exported from phpmyadmin or atleast in sql format.

Edited by urtrivedi: n/a

0

I don't think I can as it's the unis database, so I can only send it in text format.

0

Customer table:
custNum-int-4
title-varchar-20
firstName-varchar-20
familyName-varchar-30
contact-varchar-10
email-varchar-60
houseNum-varchal-10
street-varchar-20
suburb-varchar-20
state-varchar-3
postCode-varchar-4

customerCar table:
custNum-int
rego-varchar-6
make-varchar-15
model-varchar-30
yearMan-varchar-4

booking table
bookingNum-varchar-10
bookingDate-date
rego varchar-6
custNum-int

thats the tables u need and their fields and their data type and size.

0
$filter=" where Customer.custNum=customerCar.custNum and customerCar.regno=booking.regno and customerCar.custNum=booking.custNum "

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.