Jump to content

PHP / MySQL Session Problem - please help!


slibob

Recommended Posts

Hi everyone

 

I'm having trouble getting a simple PHP script to work - I'm quite new to all this, it might well be something simple

 

I have a web server running Apache, MySQL and PHP (all installed and running fine) - I have a basic shopping cart on the site (by the way its just some research and testing I'm doing for a uni course, not a real shop)

 

The MySQL table stores the items a user adds, along with their session ID

 

However, on trying to pull the info back out of the table, I get a strange error message

 

This can be seen at http://www.badgeshop.net - try adding a few things to the cart, and then view the cart (click Basket link)

 

I get the error: Unknown column 'ab9e2cd0e890f83b74b51bc21fdb0580' in 'where clause' (that's my session ID in there)

 

The script I've got on the showcart.php page is:

 

=========================

 

<?php

 

include 'lib/config.php';

include 'lib/opendb.php';

 

$display_block = "";

$display_block2 = "";

$empty=0;

 

$sess_id = session_id();

 

$get_cart = "SELECT * FROM shoppertrack WHERE session_id = $sess_id";

 

$get_cart_res = mysql_query($get_cart) or die(mysql_error());

 

if(mysql_num_rows($get_cart_res) < 1)

{

$display_block2 = "<h1>You have no items in your cart. Please <a href=\"index.php\">continue to shop</a>!</p>";

 

} else {

 

while($cart=mysql_fetch_array($get_cart_res))

{

 

$item_ref_cart = $cart['item_ref'];

 

$get_details = "SELECT item_title, item_desc, item_price FROM badges WHERE item_ref = $item_ref_cart";

 

$get_details_res = mysql_query($get_details) or die(mysql_error());

 

while($details=mysql_fetch_array($get_details_res))

{

 

$total_line = ($details[item_price])*($cart[item_qty]);

$display_block.= "<tr><td>$item_ref_cart</td><td>$details[item_title]</td><td>$details[item_desc]</td><td>$details[item_price]</td><td>$cart[item_qty]</td><td>$total_line</td><td><a href=\"removeitem.php?id=$item_ref_cart\">x</a></td></tr>";

}

 

}

}

 

?>

<html>

<head>

<title>Test</title>

</head>

<body>

<table align=center width=90%>

<tr><th>Ref</th><th>Title</th><th>Description</th><th>Price</th><th>Qty</th><th>Total</th><th></th></tr>

 

<? print $display_block2; ?>

<? print $display_block; ?>

 

</table>

</body>

</html>

 

=========================

 

Can anyone help me?  If anyone needs any more info from me, please get in touch

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/40382-php-mysql-session-problem-please-help/
Share on other sites

This is index.php:

 

==========================================

 

<?php

 

include 'lib/config.php';

include 'lib/opendb.php';

 

session_start();

 

$num_display = 12;

$cat_query = "SELECT * FROM categories";

$cat_result = mysql_query($cat_query);

 

$cat_list_block = "";

 

while($cat_row = mysql_fetch_array($cat_result, MYSQL_ASSOC))

{

$cat_list_block .= "<option value=\"{$cat_row['id']}\">{$cat_row['cat_title']}";

}

 

$query = "SELECT * FROM badges ORDER BY RAND() LIMIT 0,$num_display";

$result = mysql_query($query);

 

$display_block="<table border=0 width=50% align=center>";

$cell_count='0';

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

       

$display_block.="<td align=center width=25%><h1>{$row['badge_title']} -<br>{$row['badge_desc']}<br><br><img src=\"/images/badges/{$row['badge_image']}\" alt=\"{$row['badge_title']}\"><br><br>£{$row['badge_price']}   <a href=\"addtocart.php?ref={$row['badge_ref']}\">Buy</a><br><br></h1></td>";

        $cell_count++;

        if($cell_count==4)

{

$display_block.="</tr><tr>";

$cell_count='0';

}

}

$display_block.="</tr></table>";

 

mysql_close($conn);

?>

 

<html>

<head>

<title>BadgeShop.net</title>

<link rel=stylesheet type="text/css" href="/lib/style.css">

<body>

<p align=center>

<a href="http://www.badgeshop.net"><img src="images/main.jpg" alt="BadgeShop.net" border=0></a><br/>

<img src="images/slogan.jpg" alt="The place to buy badges on the net!"></p>

<hr/>

<p align=center>

<a href="index.php"><img src="images/m-home.jpg" border=0></a>     

<a href="info.php"><img src="images/m-info.jpg" border=0></a>     

<a href="prices.php"><img src="images/m-prices.jpg" border=0></a>     

<a href="showcart.php"><img src="images/m-basket.jpg" border=0></a>     

<a href="contact.php"><img src="images/m-contact.jpg" border=0></a><br><br></p>

 

 

<table align=center cols=2 width=60%><tr><td>

 

<form action="catsearch.php" method=get><h1><b>See all from category: 

<select name="catselect">

 

<? print $cat_list_block; ?>

 

</select> <input type=submit name="go" value="Go"></b></h1></form>

</td><td>

 

<form action="searchresults.php" method=get>

 

 

<h1><b>Search: <input type=text size=20 name=search> <input type=submit name="go" value="Go"></b></h1></form>

 

</td></tr></table>

 

<h1><center><b>A random selection of <? print $num_display; ?> of our badges:</b></h1>

 

<? print $display_block; ?>

<p align=center><a href="mailto:[email protected]">

<img src="images/bottomblurb.jpg" border=0></a>

</p>

</body>

</html>

 

==========================================

 

Thanks!

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.