Jump to content

transfering data


Hellz

Recommended Posts

<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

<?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

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

<?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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.