richard_PHP Posted April 16, 2009 Share Posted April 16, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/ Share on other sites More sharing options...
The Little Guy Posted April 16, 2009 Share Posted April 16, 2009 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811836 Share on other sites More sharing options...
Maq Posted April 16, 2009 Share Posted April 16, 2009 Extra semi-colon while ($row = mysql_fetch_array($result)) { Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811839 Share on other sites More sharing options...
The Little Guy Posted April 16, 2009 Share Posted April 16, 2009 Ahh, that is what I get for drag and drop Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811842 Share on other sites More sharing options...
richard_PHP Posted April 16, 2009 Author Share Posted April 16, 2009 okay. tried it but it now comes up with: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ******** on line 31 checked code and all seems fine, no typos or anything like that.. > Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811848 Share on other sites More sharing options...
Maq Posted April 16, 2009 Share Posted April 16, 2009 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]"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811852 Share on other sites More sharing options...
richard_PHP Posted April 16, 2009 Author Share Posted April 16, 2009 yeyy it works! 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. Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811865 Share on other sites More sharing options...
The Little Guy Posted April 16, 2009 Share Posted April 16, 2009 You never use sessions in that code... Where do you think they would go, and how would you use them? Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811868 Share on other sites More sharing options...
richard_PHP Posted April 16, 2009 Author Share Posted April 16, 2009 well the database i have was pre made by the lecturer and i dont think hed take too kindly for token tables appearing so im gonna hazard a guess at the clients computer and inserted in the cart code? Quote Link to comment https://forums.phpfreaks.com/topic/154398-shopping-problems-infinite-script-and-sessions/#findComment-811874 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.