for the life of me i cant find why this script will only work sometimes i have been working on it for the past 6 hours so any help would be welcome
<?
$additem=$POST["add"];
$account=$SESSION["account"];
$SQL = "SELECT * FROM video WHERE name LIKE '$additem'";
# execute SQL statement
$retid2 = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$retid2) { echo( mysql_error()); }
else {
# display results
while ($row24 = mysql_fetch_array($retid2)) {
$itemnumber154 = $row24["itemnumber"];
}}
$SQL = "SELECT * FROM cart WHERE account LIKE '$account'";
# execute SQL statement
$retid1 = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$retid1) { echo( mysql_error()); }
else {
# display results
while ($row23 = mysql_fetch_array($retid1)) {
$item43=$row23["itemnumber"];
$item45433=$row23["id"];
if ($item43==$itemnumber154) {$accountq=1;} else {$accountq=2;};
}}
if ($accountq==1){
$SQL = "SELECT * FROM cart WHERE id LIKE '$item45433'";
# execute SQL statement
$retid1 = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$retid1) { echo( mysql_error()); }
else {
# display results
while ($row23 = mysql_fetch_array($retid1)) {
$quanity=$row23["quanity"];
}}
$quanity1=$quanity +1;
$SQL = "UPDATE cart SET quanity = '$quanity1' WHERE id = '$item45433'";
$result = mysql_db_query($db, $SQL, $cid);
echo"$item43";
}
else {
echo"$item43";
$SQL = "SELECT * FROM video WHERE name LIKE '$additem'";
# execute SQL statement
$retid = mysql_db_query($db, $SQL, $cid);
# check for errors
if (!$retid) { echo( mysql_error()); }
else {
# display results
while ($row = mysql_fetch_array($retid)) {
$itemnumber = $row["itemnumber"];
$price = $row['price'];
}
$sql = "INSERT INTO cart (itemnumber, account, price1)
VALUES ('" . $itemnumber . "', '" . $account . "','" . $price . "');";
$result = mysql_query($sql);
if ($result) {
echo("<center><img src=logo.jpg width=331 height=265></center><p><center><b>$account</b> <i>$additem</i> has been added to your cart!!!<p></center><p><center><a href=cartview.php>click here to view shopping cart</a></center>");
} else {
echo("sorry $additem has not been added to your cart there was an error please try again");
}
}
};
//Close connection with MySQL
MySQL_close()
?>