As a newbie at 63, I have learned how to build an SQL database from scratch, interrogate it and present results, but I just cannot wrap my bhead around the following issue.

I am in the process of constructing a site that will return a list of suppliers to a particular postcode (zipcode). That bit works. However I want to add a checkmark to each record so that a customer can select which supplier provides a quote to the customer.

The values or checked records on "submit" will carry an email variable (presumably hidden) forward to a customer form which when submitted will email each supplier selected,reply to the customer.and store the details in the customer database.

The list can vary in length depending on the postcode searched. The email variable is "supplier_email" and each record has a "supplier_id" which is the primary index.

Any help would be much appreciated.

 // create the query
$result = mysql_query("SELECT * FROM `suppliers` WHERE `supplier_active` =  '1' and `supplier_deliverypostcode` LIKE '%$term%' ORDER BY `supplier_name` ASC limit 0,16");

//return the array and loop through each roww

while ($row=mysql_fetch_assoc($result)) {
	$ID = $row['supplier_id']; 
    $logo = $row['supplier_logopix'];
	$Supplier = $row['supplier_name'];
    $Phone = $row['supplier_phone1']; 
    $Price = $row['supplier_todaysprice1']; 
// concatenate to create html table row
	$tr.=  "<tr><td valign=middle><img src='/graphics/".$logo. "'></td>".
		   "<td valign=left>". $Supplier. "</td>".
		   "<td valign=middle>". $Phone. "</td>".
		   "<td valign=middle>". $Price. " ppl</td></tr>";

<table width="650" border=0 align="right" cellpadding=0 cellspacing=0 style="height: 30px; font-size: 13px; font-family: Arial, Verdana, 'Xpress SF';font-weight: normal; width: 650px; background-color: #FFF;">
      <th width="130" align="left" valign="middle" style="text-align: middle; color: #333; ;"> Logo</th>
      <th width="230" align="left" valign="middle" style="text-align: middle; color: #333;"> Supplier</th>
      <th width="135" align="left" valign="middle" style="text-align: middle; color: #333;"> Phone</th>
      <th width="155" align="left" valign="middle" style="text-align: middle; color: #333;"> Current Price</th>

5 Years
Discussion Span
Last Post by diafol

Try to replace

while ($row=mysql_fetch_assoc($result)) {


while ($row=mysql_fetch_array($result)) {

OK, I think I know what you're trying to do:

$tr.=  "<tr><td valign=middle><img src='/graphics/".$logo. "'></td>".
		   "<td valign=left>". $Supplier. "</td>".
		   "<td valign=middle>". $Phone. "</td>".
		   "<td valign=middle>". $Price. " ppl</td>
                   "<td valign=middle><input type=\"checkbox\" name=\"check[]\" value=\"$ID\" /></td></tr>";

that's the checkbox with name as check[] - this will create a $_POST array after form submit. You need to place form tags around your table.

Then for the actual table header, add this (change the html attributes as you see fit):

<th width="155" align="left" valign="middle" style="text-align: middle; color: #333;"> Select</th>

Your form handling page could then have this:

$check = (array)$_POST['check'];

that will place all the selected ID values into $check as an array. Use the values to build up a WHERE clause to use in a SELECT query to retrieve all the data (email??) from those records that you require.
Use the emails to build up a "TO" field OR better still perhaps, if you don't want each supplier to see that the user has sent to their competitors, use the BCC field OR loop through and send individual mails.

I don't know if this is what you want. BTW - congrats on picking up php at 63!


Try to replace

while ($row=mysql_fetch_assoc($result)) {


while ($row=mysql_fetch_array($result)) {

Thanks for that. Have changed this code. Seems to run faster!


Thanks Ardav,

Still having some issues with the last line of code. I understand the code but I am getting syntax error on your added line.

Also where do I need to put the 'Form" Quotes?

I did create a variable $ID = 'supplier_id'

$tr.=  "<tr><td valign=middle><img src='/graphics/".$logo. "'></td>".
		   "<td valign=left>". $Supplier. "</td>".
		   "<td valign=middle>". $Phone. "</td>".
		   "<td valign=middle>". $Price. " ppl</td>
                   "<td valign=middle><input type=\"checkbox\" name=\"check[]\" value=\"$ID\" /></td></tr>";

that's the checkbox with name as check[] - this will create a $_POST array after form submit. You need to place form tags around your table.

"<td valign=middle>". $Price. " ppl</td>".
                   "<td valign=middle><input type=\"checkbox\" name=\"check[]\" value=\"$ID\" /></td></tr>";

Form tags:

<form method="post" action="formhandler.php">
  <input type="submit" name="subsel" value="Send" />

Edited by diafol: n/a


Well Ardav,
Guess I need to watch the syntax more closely in future. Got the code done

Now to the form tags.
Thanx a million


Thanks a million this project of mine is now got some 'balls' thanks to yor help.

Got the check boxes in place nicely and the submit button.. a graphic also in place.

Issue now is pagination which I am working on, great thing is if there are more records than 15 on the first page the submit button does not appear. So I presume it will appear on the second page after the last record.



Ardav is wise i've seen many of his posts. but I must interject djbrown, not on what he was saying... but pagination, on a form, no no no. It can be done, but I don't think it is the route you should take, you would have to store all of the variables / values coming from the first page in session or grab them from a post and set hidden fields on your second page... and then finally process them when submit button is hit. first rule of programming that I learned from a wise teacher: KISS.
Keep It Simple Stupid. Try to keep your form as simple as possible. I don't have anything to help you with a solution currently because it seems ardav has pointed you in the right direction, just trying to keep you on that narrow path.


I hear what you are saying and I have thought about it over the last two days. I have checked my data and there are occasions where the data presented to the user will not extend further than 2 pages. This gives me a maximum of 32 results. The date includes logo pix which take up the room in the listing. However, its the logos that would be identifiable straight away more so to the text to whom they relate. Its really a case of design expediency for a little extra work.


Thanks for the kind words DD :)

OK, forms and pagination, not impossible, just a bit fiddly.
Personally, I'd use javascript for this (interactively hide and show 'divs' or 'pages' or even a "scrollbox" using css by setting an overflow.

1. CSS - simplest method - put the table into a div and set a height for the div. E.g.


2. JS - hide/show method

//get php to create either one or two divved-tables depending on no. of 'pages'
//php makes page links at top of first div: [[U]1[/U]] [[U]2[/U]]
On page load first page is visible, second invisible:

<?php if($no_recs > 16)echo "<div id=\"page_nav"><a href=\"#\" id=\"f">[1]</a> <a href=\"#\" id=\"s\">[2]</a></div>";
<div id="first">
  ... do the output ...
<?php if($no_recs > 16){
echo "<div id=\"sec\" class=\"hidden\">";
... do the output ...
echo "</div>";
} ?>

That's just a quick way. Quite horrible mix of php and markup, but at least it gives you an idea. It needs a few lines of js to work and css class for hidden to display:none. Alternatively, you could use inline js 'onclick' for the page links.


Decided to go with non-pagination as I tried out a number of different scenarios prior to coding


Well I'm back again and I'm still having trouble passing a variable form page 1 of the form which is a selection form and the only variable passing from the form is the check value.

I keep getting the following message on part 2 of the form:-

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/heating1/public_html/cust_detail.php:10) in /home/heating1/public_html/cust_detail.php on line 165

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/heating1/public_html/cust_detail.php:10) in /home/heating1/public_html/cust_detail.php on line 165

So here is the code from form 1 as suggested by Ardav and this works well, I just cannot wrap my head around the checkbox requirements:-

// create the query
		$result = mysql_query("SELECT * FROM `suppliers` WHERE `supplier_active` =  '1' and `supplier_deliverypostcode` LIKE '%$term%' ORDER BY `supplier_code`,`supplier_region`,`supplier_mainpostcode` ASC");

		//return the array and loop through each roww
		while ($row=mysql_fetch_array($result)){
		$ID = $row['supplier_id']; 
		$logo = $row['supplier_logopix'];
		$region= $row['supplier_region'];
		$type = $row['supplier_type'];
		$supplier = $row['supplier_name'];
		$homepc = $row['supplier_mainpostcode'];
		$iq = $row['supplier_iq']; 
		$price = $row['supplier_todaysprice1']; 
		// concatenate to create html table row
		$tr.=  	"<tr><td width = 138><img src='/graphics/logos/".$logo. "'></td>".
		"<td width = 90>". $region. "</td>".
		"<td width = 45 align=center>". $type. "</td>".
		"<td width = 265>". $supplier. "</td>".
	   	"<td width = 40 align=center>". $homepc. "</td>".
		"<td width = 35 align=center><img src='/graphics/".$iq. "'></td>".
	    "<td width = 55 align=center><input type=\"checkbox\" name=\"check[]\" value=\"$ID\" /></td></tr>";

The connections to the database are good, so what this does is select suppliers to a specific postcode which is input at the beginning and lists them with details and a check box. User selects suppliers by checking which ones in the box. Once selected the user is forwarded to page 2 of the form, where personal details are filled in and completed, then posted to the database. All the detail post correctly except the check box selection. The check box selection will be used to send the customers details by email for quote purposes.

Here is the code for part 2 of the form:-

			    <form action="insert_customer.php" method="post">
			      <table width="622" border="0" cellspacing="0" cellpadding="0">
			          <td width="622" bgcolor="#EAEAEA" class="auto-style1"><span class="quoteform"> </span>
			            <table width="636" border="0" cellspacing="0" cellpadding="0">
			                <td width="279" height="31" bgcolor="#FFFFFF" class="auto-style1">Title</td>
			                <td width="357" bgcolor="#FFFFFF"><span class="quoteform">
			                  <select name="customer_title">
			                    <option value="Mr.">Mr.</option>
			                    <option value="Mrs.">Mrs.</option>
			                    <option value="Miss">Miss</option>
			                    <option value="Ms.">Ms.</option>
			                    <option value="Rev.">Rev.</option>
			                    <option value="Dr.">Dr.</option>
			                <td height="30" bgcolor="#FFFFFF" class="auto-style1">First Name</td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input name="customer_firstName" type="text" id="firstName" size="25" />
			                <td height="30" bgcolor="#FFFFFF" class="auto-style1">Last Name</td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input name="customer_lastName" type="text" size="30" />
			                <td height="30" bgcolor="#FFFFFF" class="auto-style1">Street</td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input name="customer_street" type="text" size="50" />
			                <td height="30" bgcolor="#FFFFFF" class="auto-style1">Street (contd)</td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input name="customer_street2" type="text" size="30" />
			                <td height="30" bgcolor="#FFFFFF" class="auto-style1">City</td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input type="text" name="customer_city" size="30"/>
			                <td height="35" bgcolor="#FFFFFF" class="auto-style1">Postcode</td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input type="text" name="customer_postcode" size="12"/>
			                <td height="35" bgcolor="#FFFFFF" class="auto-style1">County</td>
			                <td bgcolor="#FFFFFF"><select name="customer_county" type="text" style="width:165px">
			                  <option value="Aberdeenshire">Aberdeenshire</option>
			                  <option value="Angus">Angus</option>
			                  <option value="Argyllshire">Argyllshire</option>
			                  <option value="Avon">Avon</option>
			                  <option value="Ayrshire">Ayrshire</option>
			                  <option value="Banffshire">Banffshire</option>
			                  <option value="Bedfordshire">Bedfordshire</option>
			                  <option value="Berkshire">Berkshire</option>
			                  <option value="Berwickshire">Avon</option>
			                  <option value="Buckinghamshire">Buckinghamshire</option>
			                  <option value="Bute">Bute</option>
			                  <option value="Caithness">Caithness</option>
			                  <option value="Cambridgeshire">Cambridgeshire</option>
			                  <option value="Central">Central</option>
			                  <option value="Cheshire">Cheshire</option>
			                  <option value="Clackmannanshire">Clackmannanshire</option>
			                  <option value="Cleveland">Cleveland</option>
			                  <option value="Clwyd">Clywd</option>
			                  <option value="Cornwall">Cornwall</option>
			                  <option value="Cumbria">Cumbria</option>
			                  <option value="Derbyshire">Derbyshire</option>
			                  <option value="Devon">Devon</option>
			                  <option value="Dorset">Dorset</option>
			                  <option value="Dumfries and Galloway">Dumfries and Galloway</option>
			                  <option value="Dunbartonshire">Dunbartonshire</option>
			                  <option value="Durham">Durham</option>
			                  <option value="Dyfed">Dyfed</option>
			                  <option value="East Lothian">East Lothian</option>
			                  <option value="East Sussex">East Sussex</option>
			                  <option value="Essex">Essex</option>
			                  <option value="Fife">Fife</option>
			                  <option value="Gloucestershire">Gloucestershire</option>
			                  <option value="Grampian">Grampian</option>
			                  <option value="Greater Manchester">Greater Manchester</option>
			                  <option value="Gwent">Gwent</option>
			                  <option value="Gwynedd">Gwynedd</option>
			                  <option value="Hampshire">Hampshire</option>
			                  <option value="Herefordshire">Herefordshire</option>
			                  <option value="Hertfordshire">Hertfordshire</option>
			                  <option value="Highlands and Islands">Highlands and Islands</option>
			                  <option value="Humberside">Humberside</option>
			                  <option value="Invernesshire">Invernesshire</option>
			                  <option value="Isle of Wight">Isle of Wight</option>
			                  <option value="Kent">Kent</option>
			                  <option value="Kincardineshire">Kincardineshire</option>
			                  <option value="Kinross">Kinross</option>
			                  <option value="Kirkcudbrightshire">Kirkcudbrightshire</option>
			                  <option value="Lanarkshire">Lanarkshire</option>
			                  <option value="Lancashire">Lancashire</option>
			                  <option value="Leicestershire">Leicestershire</option>
			                  <option value="Lincolnshire">Lincolnshire</option>
			                  <option value="Lothian">Lothian</option>
			                  <option value="Merseyside">Merseyside</option>
			                  <option value="Mid Glamorgan">Mid Glamorgan</option>
			                  <option value="Midlothian">Midlothian</option>
			                  <option value="Morayshire">Morayshire</option>
			                  <option value="Nairnshire">Nairnshire</option>
			                  <option value="Norfolk">Norfolk</option>
			                  <option value="North Yorkshire">North Yorkshire</option>
			                  <option value="Northamptonshire">Northamptonshire</option>
			                  <option value="Northumberland">Northumberland</option>
			                  <option value="Nottinghamshire">Nottinghamshire</option>
			                  <option value="Orkney">Orkney</option>
			                  <option value="Oxfordshire">Oxfordshire</option>
			                  <option value="Peeblesshire">Peebleshire</option>
			                  <option value="Perthshire">Perthshire</option>
			                  <option value="Powys">Powys</option>
			                  <option value="Renfrewshire">Renfrewshire</option>
			                  <option value="Ross &amp; Cromarty">Ross and Cromarty</option>
			                  <option value="Roxburghshire">Roxburghshire</option>
			                  <option value="Rutland">Rutland</option>
			                  <option value="Selkirkshire">Selkirkshire</option>
			                  <option value="Shetland">Shetland</option>
			                  <option value="Shropshire">Shropshire</option>
			                  <option value="Somerset">Somerset</option>
			                  <option value="South Glamorgan">South Glamorgan</option>
			                  <option value="South Yorkshire">South Yorkshire</option>
			                  <option value="Staffordshire">Staffordshire</option>
			                  <option value="Stirlingshire">Stirlingshire</option>
			                  <option value="Strathclyde">Strathclyde</option>
			                  <option value="Suffolk">Suffolk</option>
			                  <option value="Surrey">Surrey</option>
			                  <option value="Sutherland">Sutherland</option>
			                  <option value="Tayside">Tayside</option>
			                  <option value="Tyne &amp; Wear">Tyne &amp; Wear</option>
			                  <option value="Warwickshire">Warwickshire</option>
			                  <option value="West Glamorgan">West Glamorgan</option>
			                  <option value="West Lothian">West Lothian</option>
			                  <option value="West Midlands">West Midlands</option>
			                  <option value="West Sussex">West Sussex</option>
			                  <option value="West Yorkshire">West Yorkshire</option>
			                  <option value="Wigtownshire">Wigtownshire</option>
			                  <option value="Wiltshire">Wiltshire</option>
			                  <option value="Worcestershire">Worcestershire</option>
			                <td height="27" bgcolor="#FFFFFF" class="auto-style1"><span class="auto-style11">Email Address</span></td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input type="text" name="customer_email" size="50"/>
			                <td height="27" bgcolor="#FFFFFF" class="auto-style1"><span class="auto-style11">Phone</span></td>
			                <td bgcolor="#FFFFFF"><span class="quoteform">
			                  <input type="text" name="customer_phone" size="15"/>
			                <td height="29" bgcolor="#FFFFFF" class="auto-style1">Preferred Contact by</td>
			                <td bgcolor="#FFFFFF"><label>
			                  <input type="radio" name="customer_preferredcontact" value="Email" id="customer_preferredcontact_0" />
			                    <input type="radio" name="customer_preferredcontact" value="Phone" id="customer_preferredcontact_1" />
			                <td height="38" bgcolor="#FFFFFF" >Product required</td>
			                <td bgcolor="#FFFFFF"><select name="customer_product" id="customer_product">
			                  <option value="Kerosene">Kerosene (Home Heating Oil)</option>
			                  <option value="Paraffin">Paraffin (Premium Burning Oil)</option>
			                  <option value="Gas Oil">Gas Oil (Red Diesel)</option>
			                <td height="29" bgcolor="#FFFFFF" >Quantity</td>
			                <td bgcolor="#FFFFFF"><input type="text" name="customer_quantity" id="customer_quantity" size="12" />
			                <td height="36" bgcolor="#FFFFFF" >Delivery Requested in (working days only)</td>
			                <td bgcolor="#FFFFFF"><select name="customer_delivery" size="1" id="customer_delivery">
			                  <option value="Emergency Fill">Emergency Fill 0 - 1 working day</option>
			                  <option value="2 - 3 working days">2 - 3 working days</option>
			                  <option value="4 - 6 working days">4 - 6 working days</option>
			                  <option value="7 - 9 working days">7 - 9 working days</option>
			                  <option value="10+ working days">10+ working days</option>
			                <td height="32" bgcolor="#FFFFFF" >I wish to pay the supplier by:-</td>
			                <td bgcolor="#FFFFFF"><select name="customer_payment" id="customer_payment">
			                  <option value="Credit Card">Credit Card</option>
			                  <option value="Debit Card">Debit Card</option>
			                  <option value="Cheque">Cheque</option>
			                  <option value="Bank Transfer">Bank Transfer</option>
			                  <option value="Budget Plan">Budget Plan</option>

The last part of course is posting the data to the database (the connection part is ok) all data is posted except the check details. The code is as follows:-

//$sql="INSERT INTO customer_table (All details)

$sql="INSERT INTO customer_quotes 

if (!mysql_query($sql,$con))
  die('Error: ' . mysql_error());
echo "1 Customer record added";


Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/heating1/public_html/cust_detail.php:10) in /home/heating1/public_html/cust_detail.php on line 165

This suggests that you have got a session_start() after there is output of some description e.g. html. Ensure that there is no output before the session_start().

This question has already been answered. 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.