downfall Posted October 9, 2006 Share Posted October 9, 2006 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']} - {$product['product_name']} - ".$r['size']." (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> </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? Quote Link to comment https://forums.phpfreaks.com/topic/23422-help-needed-putting-my-php-in-my-html/ Share on other sites More sharing options...
xsist10 Posted October 9, 2006 Share Posted October 9, 2006 [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> </td></tr><tr> <td>size dropdown menu</td></tr><tr> <td>submit/buy button</td></tr></table>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23422-help-needed-putting-my-php-in-my-html/#findComment-106250 Share on other sites More sharing options...
downfall Posted October 9, 2006 Author Share Posted October 9, 2006 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!! Quote Link to comment https://forums.phpfreaks.com/topic/23422-help-needed-putting-my-php-in-my-html/#findComment-106272 Share on other sites More sharing options...
xsist10 Posted October 9, 2006 Share Posted October 9, 2006 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> </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'] .' - '. $product['product_name'] .' - '. $r['size']. ' (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] Quote Link to comment https://forums.phpfreaks.com/topic/23422-help-needed-putting-my-php-in-my-html/#findComment-106293 Share on other sites More sharing options...
downfall Posted October 9, 2006 Author Share Posted October 9, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/23422-help-needed-putting-my-php-in-my-html/#findComment-106299 Share on other sites More sharing options...
downfall Posted October 9, 2006 Author Share Posted October 9, 2006 xsist10 - just me being stupid! It works fine! ;) Quote Link to comment https://forums.phpfreaks.com/topic/23422-help-needed-putting-my-php-in-my-html/#findComment-106385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.