function normal() {
$con = mysql_connect('localhost', '****', '****') or die('Could not connect to database!');
mysql_select_db('****', $con);
$sql = "(SELECT * FROM cards WHERE worth = 1 AND `deny`=0 ORDER BY RAND() LIMIT 1)";
$result2 = mysql_query($sql, $con);
if (!$result2) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result2)) {
echo "<img src=\"{$row[url]}\" alt=\"{$row[alttext]}\" /> " ;
$alt = $row['alttext'];
$collecting = "SELECT * FROM user_inventory WHERE alttext = '".$alt."' and name = '".$_COOKIE['dwtcg']['u']."' and status = 'collecting' LIMIT 1";
$collect = mysql_query($collecting);
while ($row = mysql_fetch_array($collect)) {
if($row['status'] == 'collecting') {
$sql = "SELECT * FROM `cards` WHERE alttext = '".$alt."'";
$result = mysql_query($sql, $con);
if (!$result) { echo( mysql_error()); }
while ($row = mysql_fetch_array($result)) {
$update = "UPDATE user_inventory set url = '".$row['url']."' WHERE alttext = '".$alt."' LIMIT 1";
$result = mysql_query($update);
if(!$result) { echo(mysql_error()); }
}
} elseif(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)) {
$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()); }
}
}
}
}
}
I seem to have a problem with the piece of code
It works correctly, ading and updating, but it gives this error when getting to one that needs to be updated not added
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/home/desbrina/public_html/games/insert.php on line 19
Whats causing it
Whoops, can this get moved to php forum please