I've done something here, which i cant find, no matter how much i look and test it
if(isset($_POST['Submit3'])) {
$s_num2 = "SELECT * from cards where alttext = '".htmlspecialchars($_POST['3card1'])."' OR alttext = '".htmlspecialchars($_POST['3card2'])."' OR alttext = '".htmlspecialchars($_POST['3card3'])."' OR alttext = '".htmlspecialchars($_POST['3card4'])."' OR alttext = '".htmlspecialchars($_POST['3card5'])."'";
$r_num2 = mysql_query($s_num2);
while ($row = mysql_fetch_array($r_num2)) {
$alttext = $row['alttext'];
$de = "SELECT * from user_inventory where alttext = '".$alttext."'";
$deck = mysql_query($de);
while ($row = mysql_fetch_array($deck)) {
if($row['status'] == 'collecting') {
$sql = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";
$result4 = mysql_query($sql, $con);
if (!$result4) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result4)) {
$update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alttext."' LIMIT 1";
$result = mysql_query($update);
if(!$result) { echo(mysql_error()); }
}
}
}
}
if(mysql_num_rows($deck) == 0) {
$sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alttext."'";
$result1 = mysql_query($sql1, $con);
if (!$result1) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result1)) {
$add = "INSERT INTO `desbrina_sw`.`user_inventory` (`ID` ,`name` ,`url` ,`alttext` ,`deck` ,`user_id` ,`card_id` ,`status` ,`worth` ,`amount` ,`type`) VALUES (NULL , '".$_COOKIE['dwtcg']['u']."', '".$row['url']."', '".$row['alttext']."', '".$row['deck']."', '".$_COOKIE['dwtcg']['i']."', '".$row['ID']."', 'undefined', '".$row['worth']."', '".$row['amount']."', '".$row['type']."')";
$result = mysql_query($add);
if(!$result) { echo(mysql_error()); }
}
}
echo "<br /><br />Cards added sucessfully";
//mysql_query("INSERT INTO `game` VALUES (NULL, 'doyouhave', '".$_COOKIE['dwtcg']['u']."', '" . $_SESSION['id'] . "')") or die(mysql_error());
}
What its supposed to do is check to see if the card your getting is part of your collecting set, if it is, the update the existing card, if not, then it enters it as a new row
The problem is it does random things each time
Sometimes it updates, but not inserts, sometimes it doesn't insert, other times it doesn't do anything at all