westminster86 Posted January 3, 2008 Share Posted January 3, 2008 im trying to embed some php in a htlm form action however im getting syntax errors <form action="showCart.php?new=<?php$productid?>" method="post"> dnt know if im putting the open and close php tags in the right place e suggestions Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/ Share on other sites More sharing options...
awpti Posted January 3, 2008 Share Posted January 3, 2008 <form action="showCart.php?new=<?=$productid; ?>" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429452 Share on other sites More sharing options...
simcoweb Posted January 3, 2008 Share Posted January 3, 2008 Don't think he needs that second = sign. Also, be sure that the $productid variable has a value. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429454 Share on other sites More sharing options...
The Little Guy Posted January 3, 2008 Share Posted January 3, 2008 <form action="showCart.php?new=<?=$productid; ?>" method="post"> or <form action="showCart.php?new=<?php echo $productid; ?>" method="post"> the error is probably from forgetting the semi colon. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429457 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 I would assume short tags are not supported and use his 2nd example below. Also, you don't need a semi colon if its the last line of code before a ?> <?php echo $productid ?> would work just as good. He just forgot the echo <form action="showCart.php?new=<?=$productid; ?>" method="post"> or <form action="showCart.php?new=<?php echo $productid; ?>" method="post"> the error is probably from forgetting the semi colon. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429466 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 I would assume short tags are not supported and use his 2nd example below. Also, you don't need a semi colon if its the last line of code before a ?> <?php echo $productid ?> would work just as good. He just forgot the echo <form action="showCart.php?new=<?=$productid; ?>" method="post"> or <form action="showCart.php?new=<?php echo $productid; ?>" method="post"> the error is probably from forgetting the semi colon. thanks for ur response but still no joy... syntax errors have gone but its not getting the value of the productid Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429474 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 That means $productid is empty before it hits this part of the code. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429480 Share on other sites More sharing options...
The Little Guy Posted January 3, 2008 Share Posted January 3, 2008 where do you set $productid? Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429481 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 where do you set $productid? 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?new=<?php echo $productid ?>" 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 />'; } Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429492 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 What happens when it returns false? Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429496 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 What happens when it returns false? the line of code in the form action was used with a button, but i wasnt getting the form values in this case size.... so now ive tried doing it this way and now its not passing on the value of product id Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429502 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 please dont post with your database info, can a admin or mod take the database info out please cheers........ write is the productid in a session.......... i still dont see where the productid is set........... Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429505 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 I don't see anywhere in the source code you provided where it sets the $productid. Also, next time you post the source code, it would be better to wrap them around with the BB code. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429506 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 please dont post with your database info, can a admin or mod take the database info out please cheers........ write is the productid in a session.......... i still dont see where the productid is set........... my bad im new to this site... ive taken it off... wont happen again Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429510 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 That's just for your protection so someone doesn't go in and mess with your DB. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429514 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 I don't see anywhere in the source code you provided where it sets the $productid. Also, next time you post the source code, it would be better to wrap them around with the BB code. $productid = $_GET['productid']; used at start of script after session_start() Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429515 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 I don't see anywhere in the source code you provided where it sets the $productid. Also, next time you post the source code, it would be better to wrap them around with the BB code. $productid = $_GET['productid']; used at start of script after session_start() ok ive printed the contents of the variable to see if does actually have value and it does. Its just not passing on this value on the next page where i render the output in html... so i think that there still a problem in the form action line.... i maybe wrong Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429561 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Maybe you should use $productid = $_POST['productid']; instead Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429566 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Maybe you should use $productid = $_POST['productid']; instead i tryed that Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429573 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Thats because you are still not getting any data into $productid. You use both $_GET and $_POST but where do you actually get the $productid from? It has to come from something. You use it in your FORM, but what generates it? You are trying to use a variable that has no data is the problem. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429577 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Thats because you are still not getting any data into $productid. You use both $_GET and $_POST but where do you actually get the $productid from? It has to come from something. You use it in your FORM, but what generates it? You are trying to use a variable that has no data is the problem. productid does have a value. basically on the previous page a user selects a product and this product is then passed on to the next page where the browser can view more information about the product. so they click the reference link which has the productid appened to the end of the url... so here im using get. so now they come to the show_product page.. here is where they add the product to the cart... at this stage productid has a value but then it does not pass along to the next page which is the showcartpage... ive probably confused u more now sorry Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429583 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Ok, if there is in fact a URL with this info, then $_GET is the right way. Show us the all the code that we're trying to help you with. Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429587 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Ok, if there is in fact a URL with this info, then $_GET is the right way. Show us the all the code that we're trying to help you with. $url = 'showProduct.php?productid='.($row['productid']); ive created a function where by i have a image and and url link so they can click either. everything works on this page. so then on the next page retriev this value by $productid = $_GET['productid']; and this is successful but now when i try agin to pass it on to the page where u add it to the cart its nt passing and i believ its the form action thats causing it Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429592 Share on other sites More sharing options...
westminster86 Posted January 3, 2008 Author Share Posted January 3, 2008 Ok, if there is in fact a URL with this info, then $_GET is the right way. Show us the all the code that we're trying to help you with. coding for which page? $url = 'showProduct.php?productid='.($row['productid']); ive created a function where by i have a image and and url link so they can click either. everything works on this page. so then on the next page retriev this value by $productid = $_GET['productid']; and this is successful but now when i try agin to pass it on to the page where u add it to the cart its nt passing and i believ its the form action thats causing it Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429593 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 We want to look at showCart.php don't we? Which page is having the problem, showCart or showProduct? Quote Link to comment https://forums.phpfreaks.com/topic/84325-embedding-php/#findComment-429598 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.