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!

Link to comment
Share on other sites

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>";
}
?>

Link to comment
Share on other sites

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]";
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.