ok i know why its not working..just cant figure out WHY
hope this is a bit easier to follow
simply the idcode (the value of idcode is not refreshing..ie gets defaul value all the time)
<?
//----------------checkdupe function-------------------------
function checkdupe($shirtname,$ccode,$sizeid)
{
if (isset($_COOKIE['username']))
{
$id = $_COOKIE['username'];
}
else
{
$id = $_COOKIE['notlogged'];
}
$test =$shirtname.$ccode.$sizeid;
$sql ="Select * from client_order where ordercode ='$test' and login ='$id'";
$findout = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($findout);
if ($num_rows <= 0)
{ //fail
return 0;
}
else
{ //pass
return 1;
}
}
//-----------------------------------------------------------
include("header.php");
// max width 600
if (isset($_COOKIE['username']))
{
$id = $_COOKIE['username'];
}
else
{
$id = $_COOKIE['notlogged'];
}
$sql = "select * from shirt where id = '$shirtname'";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$shirtgif = $row['gifcode'];
}
if (!isset($default))
{
// set default shirt values
$shirtname ="11";
$shirtgif ="lunch";
$colour ="black";
$sizeid ="SM";
}
if ($colour == "black")
{
$dir = "";
}
else
{
$dir = "/".$shirtgif;
}
// gets id code for database
$sql = "select * from colour where name = '$colour'";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$ccode = $row['code'];
}
// order code goes by shirt id, then colour code, then size
// EG hung like a 4 year old red small is 05RDSM
$idcode = $shirtname.$ccode.$sizeid;
//check for errors
if ($added == "yes")
{
if (checkdupe($shirtname,$ccode,$sizeid))
{
$error ="yes";
}
else
{
$error ="no";
}
}
if ($error =="no")
{
Print("<table><tr><td class='formtextred'>Item Added to Cart.</tr></td><tr><td>Choose Another Shirt to Continue</td></tr></table>");
// inserts the data into the client table for reading later
$time = time();
$sql = "Insert into client_order (login,time,ordercode,qty) Values ('$id','$time','$idcode','1')";
$result=mysql_query($sql) or die(mysql_error());
}
if ($error =="yes")
{
// still getting old idcode for some reason...why?!!!!!!
Print("<table><tr><td class='formtextred'>Sorry, that item already exists in your cart</td></tr></table>");
Print("ID COde: ".$idcode);
}
// end error checking
?>
<table width="600" height="100%" cellpadding="0" cellspacing="0">
<tr valign="center">
<td align="center">
<table width="600" cellpadding="4" cellspacing="0" style="border: solid 1px black;">
<tr valign="center" height="410">
<td align="center" colspan="6" class="formtextred">
<?
print('<img src="http://onstageshirts.com.au/shirts'.$dir.'/'.$shirtgif.$colour.'.gif">');
print('</img>');
?>
</td></tr>
<tr>
<!-- 1st cell-->
<form name="shirtname" action="<?$Php_self?>" method="post">
<td align="center" class='formtextred'>Choose Shirt<br>
<select name="shirtname" class="formselect" onChange="submit();">
<?
// gets shirts form database for select
$sql ="select * from shirt";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$selected = $row['id'] == $shirtname ? 'selected' : '';
print('<option value="'.$row['id'].'" '.$selected.'>'.$row['name']);
}
?>
</select>
</td>
<!-- 1st cell-->
<td align="center" class='formtextred'>Choose Colour<br>
<select name="colour" class="formselect" onChange="submit();">
<?
// gets shirts form database for select
$sql ="select * from colour";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$selected = $row['name'] == $colour ? 'selected' : '';
print('<option value="'.$row['name'].'"'.$selected.'>'.$row['name']);
}
?>
</select>
</td>
<!-- 3rd cell-->
<td align="center" class='formtextred'>Choose Size<br>
<select name="sizeid" class="formselect" onChange="submit();">
<?
// gets shirts form database for select
$sql ="select * from sizes";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$selected = $row['code'] == $sizeid ? 'selected' : '';
print('<option value="'.$row['code'].'" '.$selected.'>'.$row['name']);
}
?>
</select>
</td>
</tr>
<input type="hidden" name="default" value="bah">
</form>
<tr valign="center">
<td align="center" class="formtextred" colspan="3">
<?
echo'<table style="border: groove 1px black"; cellpadding="2" cellspacing="2">';
echo'<tr valign="center">';
echo'<td class="form2" style="cursor: hand;" onClick="document.getElementById(\'test\').submit();">';
// allows user to add to cart from here
?>
<form name="test" action="<?$php_self?>" method="post"><input type="hidden" name="added" value="yes">
ADD TO CART <img src="images/cart.gif" border="0">
</td></tr></table></form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
include("footer.php");
?>