Hellz Posted March 30, 2009 Share Posted March 30, 2009 <td><"a href=cart.php?ProductId=$row[ProductId]">Add Item</a></td> Im trying to get the above code to transfer data from one page to another. I have different items for sale on the sales page, the information comes from a database and i want it to transfer the data from a selected item onto the cart page. I thought the above code would put a link on the sale page saying Add item at the end of each item information that has been brought from the database. Then when the user clicks on the link it will take them to the cart page and i then want it to display the information for the item they selected. I was also wondering what the code would be that i would put on the cart page to show the information that i have transferred? Any help would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/ Share on other sites More sharing options...
micah1701 Posted March 30, 2009 Share Posted March 30, 2009 for starters, your HTML has the "quotes" in the wrong place, and your PHP is not in between PHP tags. you need something like: <td><a href="cart.php?ProductId=<?php echo $row[ProductId]; ?>">Add Item</a></td> Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-796783 Share on other sites More sharing options...
Hellz Posted March 30, 2009 Author Share Posted March 30, 2009 <?php $dbc = mysql_connect ('bbp.webcontrolcenter.com','****','****') OR die('Could not connect to MySQL : ' . mysql_error() ); mysql_select_db ('***') OR die('Could not select the database : ' . mysql_error() ); $query = "SELECT * FROM item WHERE sale='yes'"; $result = mysql_query ($query); ?> <table> <tr> <td ><strong>Artist Name</strong></td> <td ><strong>Album Name </strong></td> <td ><strong>Price </strong></td> <td ><strong>Product Description</strong></td> <td ><strong>Image</strong></td> <td ><strong>Add to Basket</strong></td> </tr> <?php while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { Echo "<tr><td>$row[Artist]</td><td>$row[Album] </td><td>$row[Price]</td><td>$row[ProductDesc]</td><td><img src=$row[image] /><td><"a href=cart.php?ProductId=$row[ProductId]">Add Item</a></td> </tr>\n"; } mysql_close(); ?> </table> ^^ that is all my current code Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-796786 Share on other sites More sharing options...
micah1701 Posted March 30, 2009 Share Posted March 30, 2009 again, your quotes in the HTML are partially to blame, try: <?php //..... echo "<tr><td>$row[Artist]</td><td>$row[Album] </td><td>$row[Price]</td><td>$row[ProductDesc]</td><td><img src=$row[image] /><td><a href=\"cart.php?ProductId=$row[ProductId]\">Add Item</a></td> </tr>\n"; //.... ?> I moved the " in your <a> tag to after the href= and then I \escaped it so it would screw up the quote marks that your echo statement is in Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-796793 Share on other sites More sharing options...
Hellz Posted March 30, 2009 Author Share Posted March 30, 2009 yea that works and transfers itas it says in the address bar. How do i then get it to display that item on the page? Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-796890 Share on other sites More sharing options...
Hellz Posted March 30, 2009 Author Share Posted March 30, 2009 <?php $dbc = mysql_connect ('bbp.webcontrolcenter.com','****','****') OR die('Could not connect to MySQL : ' . mysql_error() ); mysql_select_db ('***') OR die('Could not select the database : ' . mysql_error() ); $Prodid = $_GET['ProductId']; $query = "SELECT * FROM item WHERE ProductId=$Prodid $result=do_query($query); $row= mysql_fetch_array($result); echo "Artist . " $row['Artist] . "<br/>"; echo "Album . " $row['Album'] . "<br/>"; ?> ^^ Thats the code i got atm to show the result on the cart page but it does not work. Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-796907 Share on other sites More sharing options...
ober Posted March 30, 2009 Share Posted March 30, 2009 $query = "SELECT * FROM item WHERE ProductId=".$Prodid; Try that. If $Prodid is not an integer, you need to surround it in single quotes: $query = "SELECT * FROM item WHERE ProductId='$Prodid'"; You should also clean the input (the user can alter anything in the $_GET global array). Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-796913 Share on other sites More sharing options...
Hellz Posted March 30, 2009 Author Share Posted March 30, 2009 that doesn't work, i just get a blank screen, no banner or navigation either. any other ideas? Link to comment https://forums.phpfreaks.com/topic/151736-transfering-data/#findComment-797116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.