4 Replies - 616 Views - Last Post: 05 October 2012 - 08:39 AM Rate Topic: -----

#1 watataps123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-October 12

Shopping Cart - How to determine the cart pressed

Posted 05 October 2012 - 07:38 AM

Good day everyone, we have a project in Web Development. We only used html, css, javascript, sql and php. May I just asked how I can determine the cart ID that was clicked by the user in guitar.php and then it will direct to CART.PHP.. In cart.php, i am trying to get the id pressed by the user and then save it in a database for shopping cart.. May I ask how can i achieve this?

[GUITAR.PHP]
		<table id="table_latest" border=1><tr>
		  <?php
              $con = mysql_connect("localhost" , "root" , "");
              mysql_select_db("ppbmusix", $con);
              $query = mysql_query("SELECT * FROM tbl_ac");
              
              while($out = mysql_fetch_array($query))
			  {
				echo "<form name = 'frmProducts' action = ''".$out['ac_pic']."'' method = 'GET'" ;
				echo "<tr >" . "<td style = 'float: left;'>";
				echo "<img src='".$out["ac_pic"]."' width='300px' height = '400px'";
				echo "<br />" . "<br />" . "<br />";
				echo "</td>";	
				echo "<tr>";
				echo "<td align = 'center'>" . "<a href = 'cart.php'? id = '".$out['ac_num']."' name = 'id'> <img class = 'displayed' src = 'images/addtocart.jpg' /></a>" . "</td>" ;	
				echo "'".$out['ac_num']."'";
				echo "</tr>";
				echo "</tr>";

									    
			  }
              mysql_close($con);
          ?>
        </tr></table>  



CART.PHP
<?php
	$id = $_GET['id'];
	echo $id;
?>



I am only echoing first because I want to make sure first that it will show the right item id that was pressed and from there, i will store it to the database.

Is This A Good Question/Topic? 0
  • +

Replies To: Shopping Cart - How to determine the cart pressed

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Shopping Cart - How to determine the cart pressed

Posted 05 October 2012 - 07:47 AM

When you submit your form, what happens? Do you see id in your query string?
Was This Post Helpful? 0
  • +
  • -

#3 watataps123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-October 12

Re: Shopping Cart - How to determine the cart pressed

Posted 05 October 2012 - 08:01 AM

Wait sir, do you mean I have to use <input type = "button" > instead of a customized add to cart through image? i really had no idea on how i can get the id from the guitar.php... should i make action as cart.php and use button instead? is making a link will not work sir?
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Shopping Cart - How to determine the cart pressed

Posted 05 October 2012 - 08:08 AM

No, using a link with the GET values in the query string is about the same thing as submitting a GET form.

What you are doing in the code is essentially fine, except you've got an error in your link syntax. The end result would look something like:
<a href = 'cart.php'? id = '123' name = 'id'>


Which is invalid. The query string should be attached to the URL, not in an "id" attribute on the <a> element. It should look like:
<a href = 'cart.php?id=123' name = 'id'>



Then the $_GET["id"] in the "cart.php" script will print the "123" value.
Was This Post Helpful? 1
  • +
  • -

#5 watataps123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 05-October 12

Re: Shopping Cart - How to determine the cart pressed

Posted 05 October 2012 - 08:39 AM

thank you so much sir Atli!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1