ok, this is really strange, it now thinks its an update when its supposed to be an add, but its not actually updating anything
status is set to undefined, and the url has 12 in it, not 00, so it should be add but its updating
I'm completely stumped
Heres my whole code, hopefully you might find out the problem, as i cant
function character() {
$con = mysql_connect('localhost', '***', '***') or die('Could not connect to database!');
mysql_select_db('***', $con);
$sql = "(SELECT * FROM cards WHERE alttext in ('Qui-Gon 12', 'Obi-Wan 18') ORDER BY RAND() LIMIT 1)";
$result2 = mysql_query($sql, $con) or die(mysql_error());
while ($row = mysql_fetch_array($result2)) {
echo "<img src=\"{$row[url]}\" alt=\"{$row[alttext]}\" /> " ;
$alt = $row['alttext'];
$collecting = "SELECT * FROM test_user_inventory WHERE alttext = '".$alt."' and name = '".$_COOKIE['dwtcg']['u']."'";
$collect = mysql_query($collecting);
while ($row = mysql_fetch_array($collect)) {
$findme = '00';
$pos = strpos($row['url'], $findme);
if(($row['status'] == 'collecting') AND ($pos === false)) {
$sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alt."'";
$result1 = mysql_query($sql1, $con);
if (!$result1) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result1)) {
mysql_query("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']."')") or die(mysql_error());
echo "Add 1<br />";
}
} else {
$csql = "SELECT * FROM `cards` WHERE alttext = '".$alt."'";
$cresult = mysql_query($csql);
if (!$cresult) { echo( mysql_error()); }
while ($row = mysql_fetch_array($cresult)) {
mysql_query("UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alt."' and name = '".$_COOKIE['dwtcg']['u']."' LIMIT 1") or die(mysql_error());
echo "Update<br />";
}
}
}
if(mysql_num_rows($collect) == 0) {
$sql1 = "SELECT * FROM `cards` WHERE alttext = '".$alt."'";
$result1 = mysql_query($sql1, $con);
if (!$result1) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result1)) {
mysql_query("INSERT INTO `desbrina_sw`.`test_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']."')") or die(mysql_error());
echo "Add 2<br />";
}
}
}
}