When I run this program I get an error.
The error appears after I select the second link. I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by item_color' at line 1
I think the error points to another php file which is listed below called showitem.php
[PHP] <?php
session_start() ;
//connect to database
$conn = mysql_connect(" localhost", "nomad", "nomad") or die(mysql_error ());
mysql_select_db ("storefront_db ",$conn) or die(mysql_error ());
if ( POST[sel_item_id] != "") {
//validate item and get title and price
$get_iteminfo = "select item_title from store_items where id = POST[sel_item_id]";
$get_iteminfo_r es = mysql_query($ge t_iteminfo) or die(mysql_error ());
if (mysql_num_rows ($get_iteminfo_ res) < 1) {
//invalid id, send away
header("Locatio n: seestore.php");
exit;
} else {
//get info
$item_title = mysql_result($g et_iteminfo_res ,0,'item_title' );
//add info to cart table
$addtocart = "insert into store_shoppertr ack values ('', '$PHPSESSID', ' POST[sel_item_id]', ' POST[sel_item_qty]', ' POST[sel_item_size]', ' POST[sel_item_color]', now())";
mysql_query($ad dtocart);
//redirect to showcart page
header("Locatio n: showcart.php");
exit;
}
} else {
//send them somewhere else
header("Locatio n: seestore.php");
exit;
}
?>
[/PHP]
This code do not work...
showitem.php
[PHP]
<?php
session_start() ;
//connect to database
$conn = mysql_connect(" localhost", "nomad", "nomad") or die(mysql_error ());
mysql_select_db ("storefront_db ",$conn) or die(mysql_error ());
$display_block = "<h1>My Store - Item Detail</h1>";
//validate item
$get_item = "select c.id as cat_id, c.cat_title, si.item_title, si.item_price, si.item_desc, si.item_image from store_items as si left join store_categorie s as c on c.id = si.cat_id where si.id = GET[item_id]";
$get_item_res = mysql_query($ge t_item) or die (mysql_error()) ;
if (mysql_num_rows ($get_item_res) < 1) {
//invalid item
$display_block .= "<P><em>Inv alid item selection.</em></p>";
} else {
//valid item, get info
$cat_id = mysql_result($g et_item_res,0,' cat_id');
$cat_title = strtoupper(stri pslashes(mysql_ result($get_ite m_res,0,'cat_ti tle')));
$item_title = stripslashes(my sql_result($get _item_res,0,'it em_title'));
$item_price = mysql_result($g et_item_res,0,' item_price');
$item_desc = stripslashes(my sql_result($get _item_res,0,'it em_desc'));
$item_image = mysql_result($g et_item_res,0,' item_image');
//make breadcrumb trail
$display_block .= "<P><strong><em >You are viewing:</em><br><a href=\"seestore .php?cat_id=$ca t_id\">$cat_tit le</a> > $item_title</strong></p>
<table cellpadding=3 cellspacing=3>
<tr>
<td valign=middle align=center><i mg src=\"$item_ima ge\"></td>
<td valign=middle>< P><strong>Descr iption:</strong><br>$ite m_desc</p>
<P><strong>Pric e:</strong> \$item_price</p>
<form method=post action=\"addtoc art.php\">";
//get colors
$get_colors = "select item_color from store_item_colo r where item_id = $item_id order by item_color";
$get_colors_res = mysql_query($ge t_colors) or die(mysql_error ());
if (mysql_num_rows ($get_colors_re s) > 0) {
$display_block .= "<P><strong>Ava ilable Colors:</strong>
<select name=\"sel_item _color\">";
while ($colors = mysql_fetch_arr ay($get_colors_ res)) {
$item_color = $colors['item_color'];
$display_block .= "<option value=\"$item_c olor\">$item_co lor</option>";
}
$display_block .= "</select>";
}
//get sizes
$get_sizes = "select item_size from store_item_size where item_id = $item_id order by item_size";
$get_sizes_res = mysql_query($ge t_sizes) or die(mysql_error ());
if (mysql_num_rows ($get_sizes_res ) > 0) {
$display_block .= "<P><strong>Ava ilable Sizes:</strong>
<select name=\"sel_item _size\">";
while ($sizes = mysql_fetch_arr ay($get_sizes_r es)) {
$item_size = $sizes['item_size'];
$display_block .= "
<option value=\"$item_s ize\">$item_siz e</option>";
}
$display_block .= "</select>";
}
$display_block .= "
<P><strong>Sele ct Quantity:</strong>
<select name=\"sel_item _qty\">";
for($i=1; $i<11; $i++) {
$display_block .= "<option value=\"$i\">$i </option>";
}
$display_block .= "
</select>
<input type=\"hidden\" name=\"sel_item _id\" value=\" GET[item_id]\">
<P><input type=\"submit\" name=\"submit\" value=\"Add to Cart\"></p>
</form>
</td>
</tr>
</table>";
}
?>
<HTML>
<HEAD>
<TITLE>My Store</TITLE>
</HEAD>
<BODY>
<?php echo $display_block; ?>
</BODY>
</HTML>
[/PHP]
any help would be great. If you need to see my db tables please let me know
thanks
nomad
ps sorry the tag for php is missing up my php code.
The error appears after I select the second link. I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by item_color' at line 1
I think the error points to another php file which is listed below called showitem.php
[PHP] <?php
session_start() ;
//connect to database
$conn = mysql_connect(" localhost", "nomad", "nomad") or die(mysql_error ());
mysql_select_db ("storefront_db ",$conn) or die(mysql_error ());
if ( POST[sel_item_id] != "") {
//validate item and get title and price
$get_iteminfo = "select item_title from store_items where id = POST[sel_item_id]";
$get_iteminfo_r es = mysql_query($ge t_iteminfo) or die(mysql_error ());
if (mysql_num_rows ($get_iteminfo_ res) < 1) {
//invalid id, send away
header("Locatio n: seestore.php");
exit;
} else {
//get info
$item_title = mysql_result($g et_iteminfo_res ,0,'item_title' );
//add info to cart table
$addtocart = "insert into store_shoppertr ack values ('', '$PHPSESSID', ' POST[sel_item_id]', ' POST[sel_item_qty]', ' POST[sel_item_size]', ' POST[sel_item_color]', now())";
mysql_query($ad dtocart);
//redirect to showcart page
header("Locatio n: showcart.php");
exit;
}
} else {
//send them somewhere else
header("Locatio n: seestore.php");
exit;
}
?>
[/PHP]
This code do not work...
showitem.php
[PHP]
<?php
session_start() ;
//connect to database
$conn = mysql_connect(" localhost", "nomad", "nomad") or die(mysql_error ());
mysql_select_db ("storefront_db ",$conn) or die(mysql_error ());
$display_block = "<h1>My Store - Item Detail</h1>";
//validate item
$get_item = "select c.id as cat_id, c.cat_title, si.item_title, si.item_price, si.item_desc, si.item_image from store_items as si left join store_categorie s as c on c.id = si.cat_id where si.id = GET[item_id]";
$get_item_res = mysql_query($ge t_item) or die (mysql_error()) ;
if (mysql_num_rows ($get_item_res) < 1) {
//invalid item
$display_block .= "<P><em>Inv alid item selection.</em></p>";
} else {
//valid item, get info
$cat_id = mysql_result($g et_item_res,0,' cat_id');
$cat_title = strtoupper(stri pslashes(mysql_ result($get_ite m_res,0,'cat_ti tle')));
$item_title = stripslashes(my sql_result($get _item_res,0,'it em_title'));
$item_price = mysql_result($g et_item_res,0,' item_price');
$item_desc = stripslashes(my sql_result($get _item_res,0,'it em_desc'));
$item_image = mysql_result($g et_item_res,0,' item_image');
//make breadcrumb trail
$display_block .= "<P><strong><em >You are viewing:</em><br><a href=\"seestore .php?cat_id=$ca t_id\">$cat_tit le</a> > $item_title</strong></p>
<table cellpadding=3 cellspacing=3>
<tr>
<td valign=middle align=center><i mg src=\"$item_ima ge\"></td>
<td valign=middle>< P><strong>Descr iption:</strong><br>$ite m_desc</p>
<P><strong>Pric e:</strong> \$item_price</p>
<form method=post action=\"addtoc art.php\">";
//get colors
$get_colors = "select item_color from store_item_colo r where item_id = $item_id order by item_color";
$get_colors_res = mysql_query($ge t_colors) or die(mysql_error ());
if (mysql_num_rows ($get_colors_re s) > 0) {
$display_block .= "<P><strong>Ava ilable Colors:</strong>
<select name=\"sel_item _color\">";
while ($colors = mysql_fetch_arr ay($get_colors_ res)) {
$item_color = $colors['item_color'];
$display_block .= "<option value=\"$item_c olor\">$item_co lor</option>";
}
$display_block .= "</select>";
}
//get sizes
$get_sizes = "select item_size from store_item_size where item_id = $item_id order by item_size";
$get_sizes_res = mysql_query($ge t_sizes) or die(mysql_error ());
if (mysql_num_rows ($get_sizes_res ) > 0) {
$display_block .= "<P><strong>Ava ilable Sizes:</strong>
<select name=\"sel_item _size\">";
while ($sizes = mysql_fetch_arr ay($get_sizes_r es)) {
$item_size = $sizes['item_size'];
$display_block .= "
<option value=\"$item_s ize\">$item_siz e</option>";
}
$display_block .= "</select>";
}
$display_block .= "
<P><strong>Sele ct Quantity:</strong>
<select name=\"sel_item _qty\">";
for($i=1; $i<11; $i++) {
$display_block .= "<option value=\"$i\">$i </option>";
}
$display_block .= "
</select>
<input type=\"hidden\" name=\"sel_item _id\" value=\" GET[item_id]\">
<P><input type=\"submit\" name=\"submit\" value=\"Add to Cart\"></p>
</form>
</td>
</tr>
</table>";
}
?>
<HTML>
<HEAD>
<TITLE>My Store</TITLE>
</HEAD>
<BODY>
<?php echo $display_block; ?>
</BODY>
</HTML>
[/PHP]
any help would be great. If you need to see my db tables please let me know
thanks
nomad
ps sorry the tag for php is missing up my php code.
Comment