Jump to content

Cron Problems (mysql_fetch_array)


marcus

Recommended Posts

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.4
Content-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.4
Content-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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.