Jump to content

Recommended Posts

hello this is my first time posting so i'm sorry if i word this wrong or it is a stupid question. i have a simple database made up with a product table with five fields; id, url, name, description, and price. also a categories table with five fields; id, parent_id, siteurl, name, and description. i have everything up and running,but i can't figure out how to pass the product id as a parameter. right now i have "example.php" but i need "example.php?id=1" here is what my code looks like

 

indextest.php

 

 

<?php
error_reporting(0);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Car Dealer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php



$usr = "root";
$pwd = "";
$db = "mymarket";
$host = "localhost";

//connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}


	$category = "";

	// setup SQL statement
	$SQL = " SELECT * FROM categories ";
	$SQL = $SQL . " WHERE parent_id = '0' ";

// execute SQL statement
		$retid = mysql_db_query($db, $SQL, $cid);

		// check for errors
		if (!$retid) { echo( mysql_error()); }
		else {



?>

<div id="layout">
  <div id="titlebg">
    <div class="title">CAR</div>
    <div class="title1">DEALER</div>
    <div class="title2">WE HAVE</div>
    <div class="title3">THE BEST CARS</div>
    <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div>
  </div>
  <hr id="hrline" />
  <div id="gradientbg">
    <div id="links">
<h2>
      <?php
      	// display results
  				echo ("<p><dt><b>$category</b><br>\n");
  				while ($row = mysql_fetch_array($retid)) {
  					$siteurl = $row["siteurl"];
  				$name = $row["name"];

  			 echo ("<dd><a href='$siteurl'>$name</a></dd>\n<br>");
  											}
  			echo ("</dt></p>");
  			}
  			



     ?>
<h2/>
    </div>
    <div id="header"></div>
  </div>
  <div id="bodypart">
    <div id="catalogue">
      <div class="cat">CATALOGUE</div>
      <div id="cat1"></div>
      <div id="car1"></div>
      <div id="cat2"></div>
      <div id="car2"></div>
    </div>
    <div id="line"></div>
    <div id="ourservices">
      <div class="our">OUR SERVICES</div>
      <div id="pic1"></div>
      <div class="lorem">Lorem ipsum</div>
      <div class="txt">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div>
    </div>
    <div id="line1"></div>
    <div id="aboutus">
      <div class="abt">ABOUT US</div>
      <div id="pic2"></div>
      <div class="lorem1">Lorem ipsum</div>
      <div class="txt1">At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam At vero eos et accusam sed diam nonumy eirmod Erat, sed diam voluptua. At vero eos et accusam Consetetur sadi pscing </div>
    </div>
  </div>
  <hr id="hrline1" />
  <div class="foottxt">Copyright © Cars.  Design by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>.</div>
</div>
</body>
</html>


 

and i would like to link that to this next file att.php

 


<?php
error_reporting(0);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Smartphone Dealer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php



$usr = "root";
$pwd = "";
$db = "mymarket";
$host = "localhost";

//connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}


	$category = "";

	// setup SQL statement
	$SQL = " SELECT * FROM categories ";
        $SQL = $SQL . " WHERE id ='4' OR id = '5' OR id = '6' ";



?>

<div id="layout">
  <div id="titlebg">
    <div class="title">SMARTPHONE</div><br>
    <div class="title1">DEALER</div>
    <div class="title2">WE HAVE</div>
    <div class="title3">NO CONTRACT SMARTPHONES</div>
    <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div>
  </div>
  <hr id="hrline" />
  <div id="gradientbg">
<h3>
<?php

// execute SQL statement
		$retid = mysql_db_query($db, $SQL, $cid);

		// check for errors
		if (!$retid) { echo( mysql_error()); }
		else {

			// display results
			echo ("<p><dt><b>$category</b><br>\n");
			while ($row = mysql_fetch_array($retid)) {
				$siteurl = $row["siteurl"];
			$description = $row["description"];

			echo ("<dd><a href='$siteurl'>$description</a></dd>\n<br>");
										}
		echo ("</dt></p>");

}

?>

    </div>
<h3>


  </div>
  <hr id="hrline1" />
  <div class="foottxt">Copyright © Nathan Hein.  Template by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>. <br>
  DISCLAIMER: This website was designed for a school project and is not intended for commercial use of any kind.</div>



</div>
</body>
</html>


 

i know i probably have a lot of problems with this code, but the one i can't figure out is passing the parameter and i have been looking at forums, websites, w3schools, everywhere. i;m just not grasping the concept of how to make it work with this. 

 

thank you so much for any input

Basically you would need to assign a variable with $_GET

http://www.w3schools.com/php/php_get.asp

 

Here's a phpfreaks post with some explanation and a demo example code.

http://www.phpfreaks.com/forums/index.php?topic=331915.msg1562195#msg1562195

Let's say from the first script you want it to be a hyperlink and pass that value to a second script.

 

script1.php

<?php
$id = 35;
echo "<a href='script2.php?id=$id'>Go to script2 with ID $id</a>";
?>
Or can do the hyperlink something like this way.
<a href="script2.php?id=<?php echo $id;?>">Go to script2 with ID <?php echo $id;?></a>

 

script2.php

<?php
$id = $_GET['id'];
echo $id."<br />";
?>

thanks for all of the help i almost have it working. i am to the point where i have category.php passing the category id to the product page, but at the product page when i click on the product link the next page only displays the product id that i got with the $_GET['id'];

here is what i have any help would really be appreciated

 


<?php
error_reporting(0);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Smartphone Dealer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php



$usr = "root";
$pwd = "";
$db = "mymarket";
$host = "localhost";

//connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n");	}


	$products = "";

	// setup SQL statement
	$id=$_GET['id'];
	$SQL = "SELECT * FROM products WHERE id = '$id'";
                




?>

<div id="layout">
  <div id="titlebg">
    <div class="title">SMARTPHONE</div><br>
    <div class="title1">DEALER</div>
    <div class="title2">WE HAVE</div>
    <div class="title3">NO CONTRACT SMARTPHONES</div>
    <div class="title4" align="center"> Links: <a target="_blank" href="http://jigsaw.w3.org/css-validator/" class="title4">CSS VALIDATOR</a></div>
  </div>
  <hr id="hrline" />
  <div id="gradientbg">
<h3>
<?php

// execute SQL statement
		$retid = mysql_db_query($db, $SQL, $cid);

		// check for errors
		if (!$retid) { echo( mysql_error()); }
		else {

			// display results
			echo ("<p><dt><b>$id</b><br>\n");

			while ($row = mysql_fetch_array($retid)) {
				$name = $row["name"];
			$description = $row["description"];

		    $price = $row["price"];


			echo ("<dd>$name</dd>\n<br>$description<br>$price");
										}
		echo ("</dt></p>");

}

?>

    </div>
<h3>


  </div>
  <hr id="hrline1" />
  <div class="foottxt">Copyright © Nathan Hein.  Template by <a href="http://www.dotcominfoway.com/" class="foottxt">DOT COM INFOWAY</a>. <br>
  DISCLAIMER: This website was designed for a school project and is not intended for commercial use of any kind.</div>



</div>
</body>
</html>


 

it seems like it is selecting the id i passed in with

 

$id=$_GET['id'];

$SQL = "SELECT * FROM products WHERE id = '$id'";

 

but the id will display and not the product name price etc..

               

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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