Am new to SQL and PHP. Only been using them for about 3 weeks to create an e-commerce site for some friends. I have been trying to set up a link to paypal's shopping basket feature from my listing page. I'm trying to get the link to appear next to each row in my listing so that it extracts the rows values and sends them through to the shopping basket. Here is the script for the page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- This site was created by Huw Hughes - huw_hughes712@hotmail.com -->
<HTML><HEAD>
<TITLE></title>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="website/Page1_files/page.css" rel=stylesheet>
<META content="Microsoft FrontPage 5.0" name=GENERATOR>
<META http-equiv=Last-Modified content=22/05/2004:08:35:13>
<META http-equiv=Pragma content=no-cache></HEAD>
<BODY>
<div align="center">
<center>
<table cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family:Arial Black; color:#FFFFFF; text-align:center" bordercolor="#000000" width="80%" id="AutoNumber1" bgcolor="#003163">
<tr>
<td width="100%" colspan="8" align="center" valign="top" height="1" bgcolor="#FFFFFF">
<img border="0" src="headlight_protectors_files/Alfa_romeo_Logo.jpg"></td>
</tr>
<tr>
<td width="100%" height="24" align="center" colspan="8" bgcolor="#000000">
<font face="Arial Black" size="4" color="#FFFFFF">Headlight Protectors</font></td>
</tr>
<tr>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Part Number</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Make</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Model</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<p align="center"><font face="Arial Black" color="#FFFFFF">Year Range</font></td>
<td width="23%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Description</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Price</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Shipping Cost</font></td>
<td width="5%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
&nbsp;</td>
</tr>
<tr>
<?php
$db = mysql_connect("HOST_NAME","DB_NAME","DB_PASSWORD");
mysql_select_db("DB_NAME",$db);
$result = mysql_query("SELECT * FROM Items WHERE Category=35",$db);
while ($myrow = mysql_fetch_row($result)) (
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[7], $mysql[8]));
echo "</table>\n";
?>
</tr>
</table>
</div>
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="PAYPAL_ACCOUNT_USERNAME">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/view_cart_02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="display" value="1">
</form>
<!-- This site was created by Huw Hughes - huw_hughes712@hotmail.com -->
<p>&nbsp;</p>
</BODY></HTML>


and here is the script for the paypal link:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="PAYPAL_ACCOUNT_USERNAME">
<input type="hidden" name="item_name" value="ITEM_NAME_FROM_DB">
<input type="hidden" name="item_number" value="ITEM_NUMBER_FROM_DB">
<input type="hidden" name="amount" value="COST_FROM_DB">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
</form>

Please could someone help me with this as I have run out of ideas.

Thanks
Huw

Hey Huw,

You'll need to do something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- This site was created by Huw Hughes - [email]huw_hughes712@hotmail.com[/email] -->
<HTML><HEAD>
<TITLE></title>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="website/Page1_files/page.css" rel=stylesheet>
<META content="Microsoft FrontPage 5.0" name=GENERATOR>
<META http-equiv=Last-Modified content=22/05/2004:08:35:13>
<META http-equiv=Pragma content=no-cache></HEAD>
<BODY>
<div align="center">
<center>
<table cellpadding="0" cellspacing="0" style="border-collapse: collapse; font-family:Arial Black; color:#FFFFFF; text-align:center" bordercolor="#000000" width="80%" id="AutoNumber1" bgcolor="#003163">
<tr>
<td width="100%" colspan="8" align="center" valign="top" height="1" bgcolor="#FFFFFF">
<img border="0" src="headlight_protectors_files/Alfa_romeo_Logo.jpg"></td>
</tr>
<tr>
<td width="100%" height="24" align="center" colspan="8" bgcolor="#000000">
<font face="Arial Black" size="4" color="#FFFFFF">Headlight Protectors</font></td>
</tr>
<tr>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Part Number</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Make</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Model</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<p align="center"><font face="Arial Black" color="#FFFFFF">Year Range</font></td>
<td width="23%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Description</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Price</font></td>
<td width="12%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
<font face="Arial Black" color="#FFFFFF">Shipping Cost</font></td>
<td width="5%" height="30" background="headlight_protectors_files/top_bg.jpg" align="center">
&nbsp;</td>
</tr>
<?php
$db = mysql_connect("HOST_NAME","DB_NAME","DB_PASSWORD");
mysql_select_db("DB_NAME",$db);
$result = mysql_query("SELECT * FROM Items WHERE Category=35",$db);
while ($myrow = mysql_fetch_row($result))
{
	$paypal_code = '<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
					<input type="image" src="https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!">
					<input type="hidden" name="add" value="1">
					<input type="hidden" name="cmd" value="_cart">
					<input type="hidden" name="business" value="PAYPAL_ACCOUNT_USERNAME">
					<input type="hidden" name="item_name" value="'.$myrow[0].'">
					<input type="hidden" name="item_number" value="'.$myrow[1].'">
					<input type="hidden" name="amount" value="'.$myrow[2].'">
					<input type="hidden" name="no_note" value="1">
					<input type="hidden" name="currency_code" value="GBP">
					</form>';
	printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
	$myrow[0], $myrow[1], $myrow[2], $myrow[3], $myrow[4], $myrow[5], $myrow[7], $paypal_code));
}
?>
</table>
</div>
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="PAYPAL_ACCOUNT_USERNAME">
<input type="image" src="https://www.paypal.com/en_GB/i/btn/view_cart_02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="display" value="1">
</form>
<!-- This site was created by Huw Hughes - [email]huw_hughes712@hotmail.com[/email] -->
<p>&nbsp;</p>
</BODY></HTML>

It's also good practice to clean-up when you're finished with your MySQL results:

@mysql_free_result($result);

This would go at the end of your while loop

I'm sure Huw would have found this information very helpful - three years ago :P

Still, perhaps someone else will have a similar need and find it here now.

Hehe, sorry, my bad. I suppose that's what you get for answering at 3am on a Sunday morning.

You'll probably see a couple of others where I didn't read the date...

I'll apologise now in advance :$