Jump to content

Help needed putting my PHP in my HTML!


downfall

Recommended Posts

Hi,

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

Here is the PHP:

[code]$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>
<?
}
?>[/code]

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

[code]<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>
                        [/code]

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

[code]
<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>
[/code]
Link to comment
Share on other sites

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


It needs to go inplace of

[code]
{$product['product_name']}

<br>

{$product['category_name']}

<br>

{$product['band_name']}

<br>

{$product['product_price']}
[/code]

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!!
Link to comment
Share on other sites

I think this is what you want.

[code]
<?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>

<?
}
?>

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.