Jump to content


Photo

Help needed putting my PHP in my HTML!


  • Please log in to reply
5 replies to this topic

#1 downfall

downfall
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 09 October 2006 - 01:14 PM

Hi,

I'm getting errors trying to put my PHP code into my HTML. Can anyone help?

Here is the PHP:

$cat = $_GET['id'];

$sql = "SELECT p.product_name, p.product_price, b.band_name, c.category_name, p.product_id
        FROM products p
        INNER JOIN band_products bp ON p.product_id = bp.product_id
        INNER JOIN bands b ON bp.band_id = b.band_id
        INNER JOIN categories c ON c.category_id = p.category_id
        WHERE p.category_id = '$cat'
        ORDER BY p.product_name, b.band_name";
$result = mysql_query($sql) or die (mysql_error());
while ($product = mysql_fetch_array($result, MYSQL_ASSOC)){

echo "

{$product['product_name']}

<br>

{$product['category_name']}

<br>

{$product['band_name']}

<br>

{$product['product_price']}

<br>

<FORM METHOD=\"POST\" ACTION=\"http://ww6.aitsafe.com/cf/add.cfm\">
    <INPUT TYPE=\"HIDDEN\" NAME=\"userid\" VALUE=\"88166920\">
    <INPUT TYPE=\"HIDDEN\" NAME=\"price\" VALUE=\"{$product['product_price']}\">
    <INPUT TYPE=\"HIDDEN\" NAME=\"units\" VALUE=\"0.3\">
    <INPUT TYPE=\"HIDDEN\" NAME=\"return\" VALUE=\"http://www.spiral-scandinavia.com/return_mals.asp?doc=http://www.spiral-scandinavia.com/catalog/tshirts/index.asp\">
    <SELECT NAME=\"product\" SIZE=\"1\">";

$size_sql = "SELECT size, stock_level FROM products LEFT JOIN prod_size ON products.product_id = prod_size.product_id WHERE products.product_id = '".$product['product_id']."' AND stock_level > 0";
  $res = mysql_query($size_sql) or die (mysql_error());
    while($r = mysql_fetch_array($res)){
    echo "<option VALUE=\"{$product['band_name']}&nbsp;-&nbsp;{$product['product_name']}&nbsp;-&nbsp;".$r['size']."&nbsp;(Category: {$product['category_name']})\">".$r['size']."</option>";
    }
?>
        </SELECT><br><br>
    <input TYPE="submit" value="Buy Now" border="0" NAME="Order">
    </form>
<?
}
?>

And I would like to merge it into this simple bit of HTML I've taken from my webpage:

<table width="180" border="0" cellspacing="0" cellpadding="0" align="center">
                            <tr> 
                              <td>product name here</td>
                            </tr>
                            <tr> 
                              <td>band name here</td>
                            </tr>
                            <tr> 
                              <td>category name here</td>
                            </tr>
                            <tr> 
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td>size dropdown menu</td>
                            </tr>
                            <tr> 
                              <td>submit/buy button</td>
                            </tr>
                          </table>
                       

In the HTML I've put in the <td> tags where I want the PHP to be echoed. Can anyone help me with this?

#2 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 02:16 PM

<table width="180" border="0" cellspacing="0" cellpadding="0" align="center">
<tr> 
     <td> <?php echo $product["product_name"]; ?> </td>
</tr>
<tr> 
     <td> <?php echo $product["band_name"]; ?> </td>
</tr>
<tr> 
     <td> <?php echo $product["category_name"]; ?> </td>
</tr>
<tr> 
     <td>&nbsp;</td>
</tr>
<tr>
     <td>size dropdown menu</td>
</tr>
<tr> 
     <td>submit/buy button</td>
</tr>
</table>

SA PHP Archives - www.phparchives.za.org

#3 downfall

downfall
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 09 October 2006 - 02:51 PM

Could you insert the html table into the whole PHP code?


It needs to go inplace of

{$product['product_name']}

<br>

{$product['category_name']}

<br>

{$product['band_name']}

<br>

{$product['product_price']}

What you have done works but it doesn't when I try and merge it together with all the other PHP code!! I've been trying for 2 hours now and gotten nowhere!!

#4 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 09 October 2006 - 03:26 PM

I think this is what you want.

<?php
$cat = $_GET['id'];

$sql = "SELECT p.product_name, p.product_price, b.band_name, c.category_name, p.product_id "
      ."FROM products p "
      ."INNER JOIN band_products bp ON p.product_id = bp.product_id "
      ."INNER JOIN bands b ON bp.band_id = b.band_id "
      ."INNER JOIN categories c ON c.category_id = p.category_id "
      ."WHERE p.category_id = '$cat' "
      ."ORDER BY p.product_name, b.band_name";
$result = mysql_query($sql) or die (mysql_error());

while ($product = mysql_fetch_array($result, MYSQL_ASSOC)){

?>
	<FORM METHOD="POST" ACTION="http://ww6.aitsafe.com/cf/add.cfm">
	<INPUT TYPE="HIDDEN" NAME="userid" VALUE="88166920">
    <INPUT TYPE="HIDDEN" NAME="price" VALUE="<?php echo $product['product_price']; ?>">
    <INPUT TYPE="HIDDEN" NAME="product_id" VALUE="<?php echo $product['product_id']; ?>">
    <INPUT TYPE="HIDDEN" NAME="units" VALUE="0.3">
    <INPUT TYPE="HIDDEN" NAME="return" VALUE="http://www.spiral-scandinavia.com/return_mals.asp?doc=http://www.spiral-scandinavia.com/catalog/tshirts/index.asp">
    
	<table width="180" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr> 
		<td><?php echo $product['product_name']; ?></td>
	</tr>
	<tr> 
		<td><?php echo $product['band_name']; ?></td>
	</tr>
	<tr> 
		<td><?php echo $product['category_name']; ?></td>
	</tr>
	<tr> 
		<td><?php echo printf("%0.2f", $product['product_price']); ?></td>
	</tr>
	<tr> 
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>
			<SELECT NAME="product" SIZE="1">";

			<?php

				$size_sql = "SELECT size, stock_level FROM products LEFT JOIN prod_size ON products.product_id = prod_size.product_id WHERE products.product_id = '".$product['product_id']."' AND stock_level > 0";
				$res = mysql_query($size_sql) or die (mysql_error());
				while($r = mysql_fetch_array($res)){
					echo '<option VALUE="'. $product['band_name'] .'&nbsp;-&nbsp;'. $product['product_name'] .'&nbsp;-&nbsp;'. $r['size']. '&nbsp;(Category: '. $product['category_name'] .')">'.$r['size'].'</option>';
			    }
			?>
			
			</SELECT><br><br>
		</td>
	</tr>
	<tr> 
		<td> <input TYPE="submit" value="Buy Now" border="0" NAME="Order"> </td>
	</tr>
	
	</table>
	</form>
 
<?
}
?>


SA PHP Archives - www.phparchives.za.org

#5 downfall

downfall
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 09 October 2006 - 03:36 PM

I don't understand!! Still getting nothing, not even the space the table rows give appear on the site!! And nothing it echoed, no text despite getting no errors!

#6 downfall

downfall
  • Members
  • PipPipPip
  • Advanced Member
  • 61 posts

Posted 09 October 2006 - 06:03 PM

xsist10 - just me being stupid! It works fine! ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users