Jump to content

shopping problems (infinite script and sessions)


richard_PHP

Recommended Posts

back again this time with a pain in the bum one. no matter how hard i try i just get that infinite script of doom business going on.

 

scenario: try and make a basic shopping basket and add ajax on for extra features. that bits fine, only when you click ADD TO CART then the code just has the '$make - $model' repeated over and over in that loop.

 

helpings please! :(

 

CODE:

        <?php
		$conn = mysql_connect("***", "***", "***");
		mysql_select_db("***", $conn);
		$sql = "SELECT * FROM *** WHERE id = '".$_SESSION['id']."'";
		$result = mysql_query($sql, $conn);
		$row = mysql_fetch_array($result);
		while ($row) {
			echo "<p>Item: $row[make] - $row[model]</p>";
		}
	?>

 

also, there is a box in the top corner of the browser windw where you can view the current basket at any time. only it doesnt display, my conclusion is that i dont know much about sessions but tried to use them to no avail. get this infinite thing stopped first!

Try this:

 

<?php
$conn = mysql_connect("***", "***", "***");
mysql_select_db("***", $conn);
$query = "SELECT * FROM *** WHERE id = '".$_SESSION['id']."'";
$sql = mysql_query($query);
$result = mysql_query($sql, $conn);
while ($row = mysql_fetch_array($result) {
     echo "<p>Item: $row[make] - $row[model]</p>";
}
?>

You had an extra mysql_query in there:

 

$conn = mysql_connect("***", "***", "***");
mysql_select_db("***", $conn);
$sql = "SELECT * FROM *** WHERE id = '".$_SESSION['id']."'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
     echo "
Item: $row[make] - $row[model]";
}
?>

yeyy it works! :D thank you!

 

right, next up the sessions. im not really a pro and nor do i have much of a clue on how to work with them. tried the w3 schools tut on them but am still clueless. i have the session_start(); at the beginning of each php file (before <html>).

 

when a link is clicked to view the cart, its empty. :(

 

heres the script from the list of radios in case you need it:

 

<?php
    if ($_GET[make] == '') {
$where = "";
} else {
$where = " WHERE make = '".$_GET[make]."'";
}
$conn = mysql_connect("***", "***", "***");
mysql_select_db("***", $conn);
$sql = "SELECT * FROM ****" . $where;
$result = mysql_query($sql, $conn) OR die ("Cannot read from DB " . mysql_error($conn));
$rows = mysql_num_rows ($result) or die ("No entries yet.");
echo "<div align='center'><b>There are $rows radios in the DB</b></div>\n";
?>
<table border="0" cellspacing="5">
<?php
while ($row = mysql_fetch_array ($result)) {
echo "<tr><td><input type='hidden' name=".$row["id"]." value=".$row["id"]."></td><td>".$row["make"]."</td><td>".$row["model"]."</td><td>".$row["description"]."</td><td>£".$row[price]."</td><td><a href='cart1.php?id=$row[id]'>Add to Cart</a></td></tr>\n";
}
?>

 

The cart code as pasted before this.

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.