Checking against multiple tables and multiple elements in php

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 6075 Views - Last Post: 02 June 2011 - 06:18 AM Rate Topic: -----

#1 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Checking against multiple tables and multiple elements in php

Posted 31 May 2011 - 03:21 AM

Basically This is the code i have so far but i want to be able to return the values of customers based on the data entered

ie i should have the ability to enter either a "Family","Phone" or "Rego" into the form and produce a list of customers which met the criteria and use family name as a link to retrive all booking made by that name. I am getting an error on line 50 at the moment which in my text editor is the </html> and </body> tag I will have to add validation as well and would also like some advice on how to achieve this ie Hyphens, Letters and Numbers for rego but length < 8 ie "TSA-909"

<?php 
require_once("nocache.php"); // Stop information being cached
if (isset($_POST["submit"])) // Check form was submitted
  {
  
  $Family = $_POST["Family"];
  $Phone = $_POST["Phone"];
  $Rego  = $_POST ["Vehicle_Rego"];

 $conn = mysql_connect("localhost", "twastudent", "prac3"); mysql_select_db("autoservice", $conn); // Logins to Database // Connect to database
$sql = "SELECT familyName,contact,rego FROM customer,customerCar where customer.familyName = $Family ||customer.contact = '$Phone'|| customerCar.rego = $Rego";
$rs = mysql_query($sql, $conn) or die ('Problem with query' . mysql_error());
$recordcount = mysql_num_rows($rs); 
?>


<html>
<head>
<title> Find Booking Form </title>
</head>
<body>
<form id = "CustomerBooking" method = "post" action="<?php echo $_SERVER["PHP_SELF"];?>">

<label for = "Family"> Customer Family Name </label> <input type = "text" name = "Family" id = "Family"></input>
<label for = "Phone" > Customer Phone Number </label> <input type = "text" name = "Phone" id = "Phone"> </input>
<label for = "Vehicle_Rego" > Vehicle Registration Number </label> <input type = "text" name = "Vehicle_Rego" id = "Vehicle_Rego"></input>

<label for = "Submit">Submit </label> <input type = "submit" id = "Submit"> </input>

<label for = "reset" > Reset </label> <input type = "reset" id = "reset"> </input>

</form>

<?php 
echo $recordcount;
	if (mysql_num_rows($rs)> 0 )?>
	<table>
	<tr>
	<th> Customer Family Name </th> <th> Customer First Name </th> <th> Customer Suburb </th> <th> Customer Phone</th> <th> Vehicle Registraion Number </th> <th> Date Of Service Booking </th>
	</tr>
	
	<td> <?php echo $row ["familyName"];?> </td>
	<td> <?php echo $row ["contact"];?> </td>
	<td> <?php echo $row ["rego"];?> </td>


</table>
</body> </html>


I am thinking that A regular expression may be needed as that is what i would do in javascript ie rechar8 [A-Z] [a-z][0-9] && length < 9 I know this is not written correctly there to explain the concept of what i am looking at doing
Any Help Is greatly Appreciated

This post has been edited by jaimesharp: 31 May 2011 - 03:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Checking against multiple tables and multiple elements in php

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Checking against multiple tables and multiple elements in php

Posted 31 May 2011 - 03:43 AM

the if() condition from line #2 is not closed.
Was This Post Helpful? 1
  • +
  • -

#3 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Checking against multiple tables and multiple elements in php

Posted 31 May 2011 - 04:17 AM

cool i thought it was something silly i will close it and test thanks o kay i have closed this and the form loads i am getting a few warnings such as undefined row where $row is Basically the bottom php ie the section just before the table and the echos are not finding the $rs etc that is at the top of the page thanks for your speedy reply :)


I realised in a previous program i used

	<?php
		while ($row = mysql_fetch_array($rs)) { ?> <tr>
		<td><?php echo $row["firstName"]?></td>
		<td> <?php echo $row ["familyName"]?></td>
		<td> <?php echo $row ["contact"]?></td>
		<td> <?php echo $row ["suburb"]?> </td>
		<td> <?php echo $row ["rego"]?></td>
<?php } mysql_close($conn); ?> </table>



<?php 
require_once("nocache.php"); // Stop information being cached
if (isset($_POST["submit"])) // Check form was submitted
  {
  
  $Family = $_POST["Family"];
  $Phone = $_POST["Phone"];
  $Rego  = $_POST ["Vehicle_Rego"];

 $conn = mysql_connect("localhost", "twastudent", "prac3"); mysql_select_db("autoservice", $conn); // Logins to Database // Connect to database
$sql = "SELECT familyName,contact,rego FROM customer,customerCar where customer.familyName = $Family ||customer.contact = '$Phone'|| customerCar.rego = $Rego";
$rs = mysql_query($sql, $conn);

}
?>


<html>
<head>
<title> Find Booking Form </title>
</head>
<body>
<form id = "CustomerBooking" method = "post" action="<?php echo $_SERVER["PHP_SELF"];?>">

<label for = "Family"> Customer Family Name </label> <input type = "text" name = "Family" id = "Family"></input>
<label for = "Phone" > Customer Phone Number </label> <input type = "text" name = "Phone" id = "Phone"> </input>
<label for = "Vehicle_Rego" > Vehicle Registration Number </label> <input type = "text" name = "Vehicle_Rego" id = "Vehicle_Rego"></input>

<label for = "Submit">Submit </label> <input type = "submit" id = "Submit"> </input>

<label for = "reset" > Reset </label> <input type = "reset" id = "reset"> </input>

</form>
<table>

<?php 

while ($row = mysql_fetch_array($rs)) { ?> 
	
	<tr>
	<th> Customer Family Name </th> <th> Customer First Name </th> <th> Customer Suburb </th> <th> Customer Phone</th> <th> Vehicle Registraion Number </th> <th> Date Of Service Booking </th>
	</tr>
	
	<td> <?php echo $row ["Family"];?> </td>
	<td> <?php echo $row ["Phone"];?>    </td>
	<td> <?php echo $row ["Vehicle_Rego"];?>         </td>


<?php } mysql_close($conn); ?> </table>
  
</body></html>



I am getting warings on the while statement before the table about undefined rs


Quote

PHP Notice: Undefined variable: rs in \Page2.php on line 36 PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in \Page2.php on line 36 PHP Notice: Undefined variable: conn in \Page2.php on line 47 PHP Warning: mysql_close() expects parameter 1 to be resource, null given in Page2.php on line 47


I hope you can help me i am sure it is poor formatting on my part

This post has been edited by Dormilich: 31 May 2011 - 06:19 AM
Reason for edit:: pretty print formatting

Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Checking against multiple tables and multiple elements in php

Posted 31 May 2011 - 06:06 AM

Your 'OR' statement in your SQL statement may be returning an error.

$sql = "SELECT familyName,contact,rego FROM customer,customerCar where customer.familyName = $Family ||customer.contact = '$Phone'|| customerCar.rego = $Rego";


Use the keyword OR instead of ||. PHP uses ||. In Access it is used as a concatenation operator.

Also place this at the top of your page which will let you know errors and warnings your script is producing.
error_reporting(E_ALL);

Was This Post Helpful? 1
  • +
  • -

#5 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 12:28 AM

I Have changed the code though i am getting an error on line 38 which is the while loop undefined variable rs and PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given

The code is currently


<?php 
error_reporting(E_ALL);
require_once("nocache.php"); // Stop information being cached
if (isset($_POST["Submit"])) // Check form was submitted
  {
  
  $Family = $_POST["Family"];
  $Phone = $_POST["Phone"];
  $Rego  = $_POST ["Vehicle_Rego"];

$conn = mysql_connect("localhost", "twastudent", "prac3"); mysql_select_db("autoservice", $conn); // Logins to Database // Connect to database
$sql = "SELECT familyName,contact,rego FROM customer,customerCar where customer.familyName = '$Family' OR customer.contact = '$Phone' OR customerCar.rego ='$Rego'";
$rs = mysql_query($sql,$conn);

}?>


<html>
<head>
<title> Find Booking Form </title>
</head>
<body>
<form id = "CustomerBooking" method = "post" action="<?php echo $_SERVER["PHP_SELF"];?>">

<label for = "Family"> Customer Family Name </label> <input type = "text" name = "Family" id = "Family"></input>
<label for = "Phone" > Customer Phone Number </label> <input type = "text" name = "Phone" id = "Phone"> </input>
<label for = "Vehicle_Rego" > Vehicle Registration Number </label> <input type = "text" name = "Vehicle_Rego" id = "Vehicle_Rego"></input>

<label for = "Submit">Submit </label> <input type = "submit" id = "Submit"> </input>

<label for = "reset" > Reset </label> <input type = "reset" id = "reset"> </input>

</form>
<table>

<?php 
while ($row= mysql_fetch_array($rs)) { ?> 
	
	<tr>
	<th> Customer Family Name </th> <th> Customer First Name </th> <th> Customer Suburb </th> <th> Customer Phone</th> <th> Vehicle Registraion Number </th> <th> Date Of Service Booking </th>
	</tr>
	
	<td> <?php echo $row ["Family"];?> </td>
	<td> <?php echo $row ["Phone"];?>    </td>
	<td> <?php echo $row ["Vehicle_Rego"];?>         </td>


<?php  mysql_close($conn); }?> </table>
  
</body></html>





Though i would like to change it so that if matches are found
Display a table containing a list of items which meet the criteria which i have to make hyperlinks on the name though want to get the form right first


basically i think the issue is with the Select statement and lower PHP


I am thinking of using the while it is a match Display list of matches else redirect to the form and echo an error message.


Any further help on is greatly appreciated

This post has been edited by jaimesharp: 01 June 2011 - 12:55 AM

Was This Post Helpful? 0
  • +
  • -

#6 satis  Icon User is offline

  • D.I.C Head

Reputation: 82
  • View blog
  • Posts: 231
  • Joined: 26-May 11

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 05:21 AM

So, line 38 says that $rs is undefined. $rs is defined on line 13 as $rs = mysql_query($sql,$conn);. According to the PHP page on mysql_query, $rs should only come back as false if the query failed.

So, chances are your query is bad.

SELECT familyName,contact,rego FROM customer,customerCar where customer.familyName = '$Family' OR customer.contact = '$Phone' OR customerCar.rego ='$Rego'


I noticed you're querying two tables, but you're never actually specifying any relationship between the two tables. However, though I think this is a mistake, I tested it here just to play around and it doesn't actually cause an error.

So, what I would do is right after line 12 (where you defined your $sql statement), I'd just echo it out to see what's being constructed.

echo $sql .'<br>';


You can then see what's being passed to mysql.

In addition to that, right after the $rs = mysql_query($sql,$conn); line, you could put

if(!$rs)
  echo mysql_error($conn);


That way is $rs comes back false (failed), it should spit out the error message.

This post has been edited by satis: 01 June 2011 - 05:22 AM

Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 05:48 AM

View Postsatis, on 01 June 2011 - 02:21 PM, said:

I noticed you're querying two tables, but you're never actually specifying any relationship between the two tables. However, though I think this is a mistake, I tested it here just to play around and it doesn't actually cause an error.

no, it’s not an error per se. the only question is, if you get sensible output. (hard to tell here without knowledge about the table structure)

btw. the fields in the select part of the query are missing the table association.

This post has been edited by Dormilich: 01 June 2011 - 05:49 AM

Was This Post Helpful? 0
  • +
  • -

#8 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 07:43 AM

<?php 
error_reporting(E_ALL);
require_once("nocache.php"); // Stop information being cached
if (isset($_POST["Submit"])) // Check form was submitted
  {
  $conn = mysql_connect("localhost", "****", "****");
  mysql_select_db('autoservice', $conn); // Logins to Database // Connect to database
  $sql = "SELECT customer.familyName,customer.contact,customerCar.rego FROM customer,customerCar where customer.familyName = $Family OR customer.contact = $Phone OR customerCar.rego = $Rego";
   echo $sql .'<br>';
   
  $rs = mysql_query($sql,$conn);
  if(!$rs)
  echo mysql_error($conn);

  $Family = $_POST["Family"];
  $Phone = $_POST["Phone"];
  $Rego  = $_POST ["Vehicle_Rego"];
  



}?>


<html>
<head>
<title> Find Booking Form </title>
</head>
<body>
<form id = "CustomerBooking" method = "post" action="">

<label for = "Family"> Customer Family Name </label> <input type = "text" name = "Family" id = "Family"></input>
<label for = "Phone" > Customer Phone Number </label> <input type = "text" name = "Phone" id = "Phone"> </input>
<label for = "Vehicle_Rego" > Vehicle Registration Number </label> <input type = "text" name = "Vehicle_Rego" id = "Vehicle_Rego"></input>

<label for = "Submit">Submit </label> <input type = "submit" id = "Submit"> </input>

<label for = "reset" > Reset </label> <input type = "reset" id = "reset"> </input>

</form>
<table border = '1'>
<th> Customer Family Name </th> <th> Customer First Name </th> <th> Customer Suburb </th> <th> Customer Phone</th> <th> Vehicle Registraion Number </th> <th> Date Of Service Booking </th>

<?php 

		while ($row = mysql_fetch_array($rs)) { ?> <tr>
	<td> <?php echo $row ["Family"];?> </td>
	<td> <?php echo $row ["Phone"];?>    </td>
	<td> <?php echo $row ["Vehicle_Rego"]; } ?>         </td>
	</tr>
<?php  mysql_close($conn);?> </table>
</body></html>



okay i have added the table associations



i will attach a copy of the table structure for clarification i am not getting any output



With the code in this post i am getting the following errors

PHP Notice: Undefined variable: rs in Page3.php on line 46 PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in Page3.php

on line 46 PHP Notice: Undefined variable: conn Page3.php on line 51

PHP Warning: mysql_close() expects parameter 1 to be resource, null given in Page3.php on line 51


I cannot figure this out as to why these errors are occurring Here is the table structure Attached File  TableSructure.pdf (379.26K)
Number of downloads: 59


Maybe it is my select i tried using the echo of RS to see what is outputted though it should be what i enter into the form ie familyname is checked against the customer table


ie $family = customer.family I think i may have the query in the wrong order

as the inputted value is to be checked against the table.

The other attached file is a copy of the data i grabbed using a simplistic php file to show the contents of the databases


though for that i used

$sql = "SELECT firstName,familyName,contact,suburb,rego from customer,customerCar"; $rs = mysql_query($sql,$conn);
?>

Attached File(s)


This post has been edited by Dormilich: 01 June 2011 - 07:53 AM
Reason for edit:: removed login credentials

Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 07:57 AM

you have closed the if() condition too early. you donít make a DB connection if there is no submit, but you donít test that for the fetching code.

that would be more clear (and easy to fix) if you would separate PHP and HTML
Was This Post Helpful? 0
  • +
  • -

#10 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 08:23 AM

I thought the if was closed too early though i got an error when i closed it later i can try to separate the php and html though i would need it for the table only so i can split it up a bit.


maybe i could use an include_once and move the $conn function there as this will be the same for all tables okay what else can i put in separate files i have limited PHP experience so can i move most of the php to an external file for testing at least looking at my current code where should the if loop end at

ie conn.php



Basically i can easily see you point i should make the connection before the if loop and then if submit occurs and a match is found display the resulting output


thanks for your diligence in helping me solve my coding

This post has been edited by jaimesharp: 01 June 2011 - 08:31 AM

Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 08:26 AM

you can put placeholders in the HTML code and replace them through PHPís str_replace() (load the HTML through file_get_contents()). then there is no need of putting PHP in the HTML.
Was This Post Helpful? 2
  • +
  • -

#12 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 08:38 AM

I have never done that can you provide an example for me


I have used the require_once before which would enable me to use it for the page though i am unsure of how to implement the methods you have outlined
Was This Post Helpful? 0
  • +
  • -

#13 satis  Icon User is offline

  • D.I.C Head

Reputation: 82
  • View blog
  • Posts: 231
  • Joined: 26-May 11

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 09:08 AM

There are actually a LOT of problems with your code. I think the following rewrite would work. I'll go into specific issues afterward. I can't test this very much locally, so there may still be problems.

<?
error_reporting(E_ALL);			//turn on error reporting
require_once("nocache.php");	// Stop information being cached
if(isset($_POST['Submit'])){
	$conn = mysql_connect("localhost", "****", "****");
	mysql_select_db('autoservice', $conn); // Logins to Database // Connect to database
	
	$Family = $_POST["Family"];
	$Phone = $_POST["Phone"];
	$Rego  = $_POST ["Vehicle_Rego"];
	
	$sql = 'SELECT cust.familyName, cust.contact, car.rego ' 
		.'FROM customer cust '
			.'JOIN customerCar car '
				.'on cust.custNum = car.custNum' 
		.'WHERE cust.familyName = "' .$Family .'"'
			.'OR cust.contact = "' .$Phone .'"'
			.'OR car.rego = "' .$Rego .'"';
	$rs = mysql_query($sql,$conn);
	if(!$rs)
		echo mysql_error($conn);
	$body = '<table><thead><tr>' 
		.'<th>Family Name</th><th>First Name</th><th>Registration Number</th></tr></thead><tbody>';
	while($row = mysql_fetch_array($rs)){
		$body .= '<tr><td>' .$row['familyName'] .'</td>' 
			.'<td>' .$row['contact'] .'</td>'
			.'<td>' .$row['rego'] .'</td>'
		.'</tr>';
	}		
	$body .= '</tbody></table>';
	mysql_close($conn);
}
else{
	$body = '<form method="POST" action="">'
		.'<label for = "Family"> Customer Family Name </label> '
			.'<input type = "text" name = "Family" id = "Family"></input><br>'
		.'<label for = "Phone" > Customer Phone Number </label> '
			.'<input type = "text" name = "Phone" id = "Phone"> </input><br>'
		.'<label for = "Vehicle_Rego" > Vehicle Registration Number </label> '
			.'<input type = "text" name = "Vehicle_Rego" id = "Vehicle_Rego"></input><br>'
		.'<label for = "Submit">Submit </label> '
			.'<input type = "submit" id = "Submit" name="Submit"> </input>'
		.'<label for = "reset" > Reset </label> '
			.'<input type = "reset" id = "reset"> </input>'
		.'</form>';
}
?>
<html>
<head>
	<title><?=$title ?></title>
</head>
<body>
	<?=$body ?>
</body>
</html>


Ok, now for the problems.

  • To see if the form is submitted you look for $_POST['Submit']. But the submit button doesn't have a name, so this check would fail.
  • In your SQL query, you never set up a relationship between your customer and customerCar tables. From the pdf provided, there is a relationship, and that relationship us between custNum fields in each table.
  • In your original script, you use $Family, $Phone and $Rego to set up your query. But you don't actually define those variables until after you set up the SQL query. You set up the $sql statement on line 8, but don't define the vars until lines 15-17.
  • Your where clause is querying varchar fields, but you don't surround the fields with quotes. This would be a SQL error.
  • Your SQL query is ripe for SQL injection. You need to clean your inputs.
  • As mentioned by Dormilich, you close your if statement before using the query results. Thus, your $rs (and all other vars) fall out of scope.
  • Your HTML for your results table is bad. You're not opening a table row tag for your header. Good form would also have you open thead and/or tbody tags. I've done so in my version.
  • On line 43, you're trying to iterate through the $rs result set, but it's out of scope as mentioned before.
  • On line 44-46, you're trying to access $rows labeled Family, Phone and Vehicle_Rego... but these aren't the field names. The field names are familyName, contact and rego.
  • On line 48, you try to close the mysql connection, but it's out of scope (as covered earlier)


I rewrote everything a bit better, I think. For once, I shoved everything into strings so we can echo it into the page fairly easily. I also corrected all the other errors, I believe, though I can't test it, so I can't be certain I didn't introduce some other problem.

This post has been edited by satis: 01 June 2011 - 09:11 AM

Was This Post Helpful? 1
  • +
  • -

#14 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 09:28 AM

Okay I will address these in order the submit button has a name and ID


The Vars were defined before the i moved them in this version i will fix that

I know Custnum is a related field though I am meant to return the specified fields though I think lastname will become a hyperlink wich posts the "Custnum" of the name clicked as the table is to produce a list of matches then if the name with the the corresponding rego etc is clicked it should redirect to another page i have to create which will list additional information about the booking


your are right about the quotes i need to add in the singlar quotations around the '$'

You are correct about the $row i should have thought that through as per On line 44-46


as this is a test page i am not worried about sql injections at the moment


I will try your code and see if it helps me thanks again for going to the trouble


Okay your code is hard to follow again i had the correct fieldnames and tables I will Have to recode alot of this to get back what i had


Now i Am Really Confused looking at this i think i have messed it up completely

<?php 
error_reporting(E_ALL);
require_once("nocache.php"); // Stop information being cached
 $conn = mysql_connect("localhost", "****", "******");mysql_select_db('autoservice', $conn); // Logins to Database // Connect to database
   $familyName = $_POST["familyName"];
  $contact = $_POST["contact"];
  $rego  = $_POST ["rego"];
$sql = "SELECT familyName,contact,rego FROM customer,customerCar where $familyName = customer.familyName OR $contact = customer.contact OR $rego = customerCar.rego";
$rs = mysql_query($sql,$conn);
if (isset($_POST["Submit"])) // Check form was submitted
  {
		while ($row = mysql_fetch_array($rs)) { ?> <tr>
	<td> <?php echo $row ["familyName"];?> </td>
	<td> <?php echo $row ["contact"];?>    </td>
	<td> <?php echo $row ["rego"]; } ?>         </td>
	</tr>
<?php  mysql_close($conn);?>

?>

<html>
<head>
<title> Find Booking Form </title>
</head>
<body>
<form id = "CustomerBooking" method = "post" action="<?php echo $_SERVER["PHP_SELF"];?>">

<label for = "familyName"> Customer Family Name </label> <input type = "text" name = "familyName" id = "familyName"></input>
<label for = "contact" > Customer Phone Number </label> <input type = "text" name = "contact" id = "contact"> </input>
<label for = "rego" > Vehicle Registration Number </label> <input type = "text" name = "rego" id = "rego"></input>

<label for = "Submit">Submit </label> <input type = "submit" id = "Submit"> </input>

<label for = "reset" > Reset </label> <input type = "reset" id = "reset"> </input>

</form>
<table border = '1'>
<th> Customer Family Name </th> <th> Customer First Name </th> <th> Customer Suburb </th> <th> Customer Phone</th> <th> Vehicle Registraion Number </th> <th> Date Of Service Booking </th>

<?php 

		while ($row = mysql_fetch_array($rs)) { ?> <tr>
	<td> <?php echo $row ["familyName"];?> </td>
	<td> <?php echo $row ["contact"];?>    </td>
	<td> <?php echo $row ["rego"]; } ?>         </td>
	</tr>
<?php  mysql_close($conn);?> </table>
<?php } ?>
</body>
</html>


I Know this isn't right at all though i had more trouble deciphering satis's code creating utter confusion on my part i knew the variables were incorrect basically i would like to submit the form to itself and if there are matches display the table with the results.


Basically I will need to return extra fields in the table though i am only searching for the matches on the defined fields.

This post has been edited by jaimesharp: 01 June 2011 - 10:19 AM

Was This Post Helpful? 0
  • +
  • -

#15 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Checking against multiple tables and multiple elements in php

Posted 01 June 2011 - 01:49 PM

View Postjaimesharp, on 01 June 2011 - 06:28 PM, said:

as this is a test page i am not worried about sql injections at the moment

wrong! where else than in a test page can you train anti SQL-Injection measures without risk? if you donít do it now, youíll do it never.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2