marcus Posted November 5, 2006 Share Posted November 5, 2006 First file:[code]<?php$connection = mysql_connect(localhost,zack_rpg,omfgg212);$db = mysql_select_db(zack_rpg,$connection);$sql111 = "SELECT * FROM stats WHERE id=$_COOKIE[id]";$res454 = mysql_query($sql111);$res1 = mysql_fetch_array($result454, MYSQL_BOTH);$mana = $res1[mana];$level = $res1[level];$ladd = $level * 20;if($mana < $ladd){$sql = "UPDATE stats SET mana = $mana + 2";$result = mysql_query($sql);}else{die();};?>[/code]Second file:[code]<?php$connection = mysql_connect(localhost,zack_rpg,omfgg212);$db = mysql_select_db(zack_rpg,$connection);$sql111 = "SELECT * FROM stats WHERE id=$_COOKIE[id]";$res454 = mysql_query($sql111);$res1 = mysql_fetch_array($result454, MYSQL_BOTH);$health = $res1[health];$level = $res1[level];$ladd = $level * 100;if($health < $ladd){$sql = "UPDATE stats SET health = $health + 10";$result = mysql_query($sql);}else{die();}?>[/code]Errors:[code]X-Powered-By: PHP/4.4.4Content-type: text/html<br /><b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/zack/public_html/rpg/cron/update_mana.php</b> on line <b>6</b><br />[/code][code]X-Powered-By: PHP/4.4.4Content-type: text/html<br /><b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/zack/public_html/rpg/cron/update_health.php</b> on line <b>6</b><br />[/code] Link to comment https://forums.phpfreaks.com/topic/26214-cron-problems-mysql_fetch_array/ Share on other sites More sharing options...
trq Posted November 5, 2006 Share Posted November 5, 2006 The result of your query is being saved into a variable called $res454, you then pass a vraible called $result454 to mysql_fetch_array().You might also want to check the query actually worked before trying to use it. The way you have your code logic now is pretty poor coding practice. Link to comment https://forums.phpfreaks.com/topic/26214-cron-problems-mysql_fetch_array/#findComment-119872 Share on other sites More sharing options...
joshi_v Posted November 6, 2006 Share Posted November 6, 2006 magallforever, It is always best to print the errors to browser (in testing servers) when you are executing a query. Try to run this code and check what are the erros it is showing.[code]<?php$connection = mysql_connect(localhost,zack_rpg,omfgg212) or die ('Connection Failed');$db = mysql_select_db(zack_rpg,$connection) or die ('Db selection failed');$sql111 = "SELECT * FROM stats WHERE id='$_COOKIE[id]' ";//Put it in single quotes if it is a number.$res454 = mysql_query($sql111) or die ($sql111.":".mysql_error());$res1 = mysql_fetch_array($res454);$mana = $res1[mana];$level = $res1[level];$ladd = $level * 20;if($mana < $ladd){$sql = "UPDATE stats SET mana = $mana + 2";$result = mysql_query($sql);}else{die();};?>[/code]Regards,Joshi. Link to comment https://forums.phpfreaks.com/topic/26214-cron-problems-mysql_fetch_array/#findComment-120268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.