westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 We want to look at showCart.php don't we? Which page is having the problem, showCart or showProduct? showcart is displaying the error but its coming from showproduct Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429601 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 We want to look at showCart.php don't we? Which page is having the problem, showCart or showProduct? showcart is displaying the error but its coming from showproduct <?php // The shopping cart needs sessions, so start one session_start(); $productid = $_GET['productid']; // get this product out of database $product = get_product_details($productid); do_html_header($product['name']); display_product_details($product); // set url for "continue button" $target = 'index.php'; if($product['catid']) { $target = 'showCat.php?catid='.$product['catid']; } // if logged in as admin, show edit product links //if(check_admin_user()) { //display_button("edit_book_form.php?productid=$productid", edit-item, 'Edit Item'); //display_button('admin.php', 'admin-menu', 'Admin Menu'); //display_button($target, 'continue', 'Continue'); } //else { display_form_button( 'add-to-cart', 'Add '.$product['name'].' To My Shopping Cart'); ?> <br /> <?php display_button($target, 'continue-shopping', 'continue Shopping'); } do_html_footer(); function get_product_details($productid) { // query database for all details for a particular product if (!$productid || $productid=='') return false; @ $db = mysql_connect(''); mysql_select_db(''); $query = "select * from products where productid='$productid'"; $result = mysql_query($query); if (!$result) return false; $result = mysql_fetch_assoc($result); return $result; } function display_product_details($product) { // display all details about this product if (is_array($product)) { echo '<table><tr>'; //display the picture if there is one if (@file_exists($product['productid'].'.jpg')) { $myproduct = GetImageSize(($product['productid'].'.jpg')); echo '<img src='.($product['productid']).'.jpg border= '.img_resize($myproduct[0], $myproduct[1], 450).' />'; } echo '<td><ul>'; echo '</li><li><b>Price:</b> £'; echo number_format($product['price'], 2); echo '</li><li><b>Colour:</b> '; echo $product['colour']; echo '<li><b>Fabric:</b> '; echo $product['fabric']; echo '</li></ul></td></tr></table>';?> <form action="showCart.php" method="post"> Select size: <select name="size"> <option value=""></option> <option value="6">6</option> <option value="8">8</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> </select> <br/> Select quantity: <select name="quantity"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <?php } else echo 'The details of this book cannot be displayed at this time.'; echo '<hr />'; } function do_html_footer() { ?> </form> </body> </html> <?php } function do_html_url($url, $name) { ?> <a href="<?php echo $url; ?>"><?php echo $name; ?></a><br /> <?php } function do_html_header($title = '') { // print an HTML header // declare the session variables we want access to inside the function if(!$_SESSION['items']) $_SESSION['items'] = '0'; if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00'; ?> <html> <head> <title><?php echo $title; ?></title> <style> h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color = red; margin = 6px } body { font-family: Arial, Helvetica, sans-serif; font-size: 13px } li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px } hr { color: #FF0000; width=70%; text-align=center} a { color: #000000 } </style> </head> <body> <table width='100%' border=0 cellspacing = 0 bgcolor='#cccccc'> <tr> <td rowspan = 2> <a href = 'index.php'><img src='Collections.jpg' alt='Collections' border=0 align='left' valign='bottom' height = 55 width = 325></a> </td> <td align = 'right' valign = 'bottom'> <?php if(isset($_SESSION['admin_user'])) echo ' '; else echo 'Total Items = '.$_SESSION['items']; ?> </td> <td align = 'right' rowspan = 2 width = 135> <?php //if(isset($_SESSION['admin_user'])) //display_button('logout.php', 'log-out', 'Log Out'); //else display_button('showCart.php', 'view-cart', 'View Cart'); ?> </tr> <tr> <td align = right valign = top> <?php if(isset($_SESSION['admin_user'])) echo ' '; else echo 'Total Price = £'.number_format($_SESSION['total_price'],2); ?> </td> </tr> </table> <?php if($title) do_html_heading($title); } function do_html_heading($title) { ?> <h3><?php echo $title; ?></h3> <?php } function img_resize($width, $height, $target) { if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } $width = round($width * $percentage); $height = round($height * $percentage); return "width=\"$width\" height=\"$height\""; } function display_button($target, $image, $alt) { echo "<center><a href=\"$target\"><img src=\"$image".".gif\" alt=\"$alt\" border=0 height =32 width = 100></a></center>"; } function display_form_button($image, $alt) { echo "<center><input type = image src=\"$image".".gif\" alt=\"$alt\" border=0 height = 32 width = 100></center>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429603 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 We want to look at showCart.php don't we? Which page is having the problem, showCart or showProduct? im still playing around with the form action line so ignore that part Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429605 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Post showProduct too. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429625 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Post showProduct too. <?php // The shopping cart needs sessions, so start one session_start(); $productid = $_GET['productid']; // get this product out of database $product = get_product_details($productid); do_html_header($product['name']); display_product_details($product); // set url for "continue button" $target = 'index.php'; if($product['catid']) { $target = 'showCat.php?catid='.$product['catid']; } // if logged in as admin, show edit product links //if(check_admin_user()) { //display_button("edit_book_form.php?productid=$productid", edit-item, 'Edit Item'); //display_button('admin.php', 'admin-menu', 'Admin Menu'); //display_button($target, 'continue', 'Continue'); } //else { display_form_button( 'add-to-cart', 'Add '.$product['name'].' To My Shopping Cart'); ?> <br /> <?php display_button($target, 'continue-shopping', 'continue Shopping'); } do_html_footer(); function get_product_details($productid) { // query database for all details for a particular product if (!$productid || $productid=='') return false; @ $db = mysql_connect('mysql12.streamline.net', 'collection', 's126655'); mysql_select_db('collection'); $query = "select * from products where productid='$productid'"; $result = mysql_query($query); if (!$result) return false; $result = mysql_fetch_assoc($result); return $result; } function display_product_details($product) { // display all details about this product if (is_array($product)) { echo '<table><tr>'; //display the picture if there is one if (@file_exists($product['productid'].'.jpg')) { $myproduct = GetImageSize(($product['productid'].'.jpg')); echo '<img src='.($product['productid']).'.jpg border= '.img_resize($myproduct[0], $myproduct[1], 450).' />'; } echo '<td><ul>'; echo '</li><li><b>Price:</b> £'; echo number_format($product['price'], 2); echo '</li><li><b>Colour:</b> '; echo $product['colour']; echo '<li><b>Fabric:</b> '; echo $product['fabric']; echo '</li></ul></td></tr></table>';?> <form action="showCart.php" method="post"> Select size: <select name="size"> <option value=""></option> <option value="6">6</option> <option value="8">8</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> </select> <br/> Select quantity: <select name="quantity"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <?php } else echo 'The details of this book cannot be displayed at this time.'; echo '<hr />'; } function do_html_footer() { ?> </form> </body> </html> <?php } function do_html_url($url, $name) { ?> <a href="<?php echo $url; ?>"><?php echo $name; ?></a><br /> <?php } function do_html_header($title = '') { // print an HTML header // declare the session variables we want access to inside the function if(!$_SESSION['items']) $_SESSION['items'] = '0'; if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00'; ?> <html> <head> <title><?php echo $title; ?></title> <style> h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color = red; margin = 6px } body { font-family: Arial, Helvetica, sans-serif; font-size: 13px } li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px } hr { color: #FF0000; width=70%; text-align=center} a { color: #000000 } </style> </head> <body> <table width='100%' border=0 cellspacing = 0 bgcolor='#cccccc'> <tr> <td rowspan = 2> <a href = 'index.php'><img src='Collections.jpg' alt='Collections' border=0 align='left' valign='bottom' height = 55 width = 325></a> </td> <td align = 'right' valign = 'bottom'> <?php if(isset($_SESSION['admin_user'])) echo ' '; else echo 'Total Items = '.$_SESSION['items']; ?> </td> <td align = 'right' rowspan = 2 width = 135> <?php //if(isset($_SESSION['admin_user'])) //display_button('logout.php', 'log-out', 'Log Out'); //else display_button('showCart.php', 'view-cart', 'View Cart'); ?> </tr> <tr> <td align = right valign = top> <?php if(isset($_SESSION['admin_user'])) echo ' '; else echo 'Total Price = £'.number_format($_SESSION['total_price'],2); ?> </td> </tr> </table> <?php if($title) do_html_heading($title); } function do_html_heading($title) { ?> <h3><?php echo $title; ?></h3> <?php } function img_resize($width, $height, $target) { if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } $width = round($width * $percentage); $height = round($height * $percentage); return "width=\"$width\" height=\"$height\""; } function display_button($target, $image, $alt) { echo "<center><a href=\"$target\"><img src=\"$image".".gif\" alt=\"$alt\" border=0 height =32 width = 100></a></center>"; } function display_form_button($image, $alt) { echo "<center><input type = image src=\"$image".".gif\" alt=\"$alt\" border=0 height = 32 width = 100></center>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429667 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Post showProduct too. that was showproduct... its this page that is not passing the value of productid to the showcart page... do u mean u want to see the showcart page? Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429679 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Both of those pages use $productid = $_GET['productid']; So one page can't send it to another if it doesn't have it. So we're back to square one, where does $productid get set. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429694 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 i saw that as well productid still not set...... Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429695 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Both of those pages use $productid = $_GET['productid']; So one page can't send it to another if it doesn't have it. So we're back to square one, where does $productid get set. those were both the same pages showproduct... u asked to see showproduct Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429697 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 PUT THIS IN ENGLISH HOW DO YOU GET THE VARABLE PRODUCTID TO GET IT'S INFO PLEASE Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429700 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Both of those pages use $productid = $_GET['productid']; So one page can't send it to another if it doesn't have it. So we're back to square one, where does $productid get set. those were both the same pages showproduct... u asked to see showproduct theres nothing wrong with the passing of values because i had this working using a button to add the contents to the cart. But i had to change it around because the button was not submitting the form values. I want the user to be able to select a size and then show the size on the cart but this wasnt working previously as it wasnt a submit button so theres nothing wrong with produtid variable its the the line form action ........ Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429703 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 SO IT THE FORM THEN NOT POSTING CORRECTLY Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429704 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 SO IT THE FORM THEN NOT POSTING CORRECTLY correct <form action="showCart.php?new= <? echo $productid; ?>" method="post"> its not outputing the value for productid Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429707 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Let's break this down a bit for you and maybe you can see where the error is since all of us are confused enough. You need to send a URL to the page that has $productid = $_GET['productid']; This URL should be something like filename.php?productid=5 for example. When the page $_GETs this id, you store it like in the $_GET statement above. The form you just posted is POSTing this to a new page called showCart.php?new=5, if and only if $productid has that info. So if it hasn't made it this far, then your ACTION and METHOD doesn't even matter yet, because it's empty. So you need to follow the variable. Find the first page of code that sets this productid, see what method it uses to pass it to another page. If you don't understand the flow, then there is no way we can. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429712 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.