Jump to content
MakeWebGames

1h work to solve the dumbest error there is


mdshare

Recommended Posts

$res = mysql_query("SELECT * FROM village");

if ($res) {
while ($newarray = mysql_fetch_array($res, mysql_assoc)) {
	$id = $newarray['id'];
	$vname = $newarray['name'];
	$vplayer = $newarray['player'];
	echo "the id of the village is ".$id." its name is ".$vname." the owner is ".$vplayer."
";
}
} else {
printf("failed: %s\n", mysql_error($mysql));
}

 

this isn't a script of mine but we have looked 1h to find the error in this small script, the error is the famous Warning: mysql_fetch_array missing argument thingy

the solution is actually very simple (deception already knows so refrain from posting please) so lets see who can find it faster than we did

Link to comment
Share on other sites

Re: 1h work to solve the dumbest error there is

it all works and really, it's a easy overlooked error something to remember when discoverd

another part of the code so that you see the stuff before it

 

mysql_connect($hostname,$username,$passwd)or die("cannot connect to db:".mysql_error());
mysql_select_db($db_name) or die (mysql_error());

mysql_query("drop table village");

  mysql_query("
     create table village(
        id int primary key,
        name varchar(75),
        x int,
        y int,
        player int,
        points int,
        rank int)");


$lines = gzfile('http://www.domain.com/x/update.txt.gz', 'r');
if(!is_array($lines)) die("File could not be opened"); 
foreach($lines as $line) {
list($id, $name,$x, $y, $player, $points, $rank) = explode(',', $line);
$name = urldecode($name);

$name = addslashes($name);
mysql_query("INSERT INTO village SET id='$id', name='$name', x='$x', y='$y', 
	player='$player', points='$points', rank='$rank'");
}
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

Re: 1h work to solve the dumbest error there is

 

mySQL commands have to be uppercase

No they don't. They are recommended to be uppercase as an easier way to recognize the MySQL syntax from regular variables. Now, the variables themself are case-sensitive.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Re: 1h work to solve the dumbest error there is

but lets see if you can fix this?

 

Warning: Wrong parameter count for mysql_fetch_assoc() in past.php on line 41

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in past.php on line 49

 

lines 38 - 49

$prize 			= array();
 	$query 			= sprintf("SELECT rank,prize FROM prizes WHERE type = 'supporter'");
 	$prizeResult	= mysql_query($query);
 	while($line = mysql_fetch_array($prizeResult)){
 		$prize[$line[0]] = $line[1];
 	}
 	$query	= sprintf("SELECT id,pimp,networth,online,rank,nrank,status,online FROM %s WHERE status='supporter' ORDER BY nrank ASC limit 10", $pTable);
 	//echo $query;
 	$supResult = mysql_query($query);

 	$i = 1;
 	while($line = mysql_fetch_assoc($supResult,MYSQL_ASSOC)){
 		if($rankstart==0){$rankcolor="#220000";$rankstart++;}
Link to comment
Share on other sites

Re: 1h work to solve the dumbest error there is

now i a getting

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in past.php on line 49

 

line 49

while($line = mysql_fetch_array($supResult,MYSQL_ASSOC)){
Link to comment
Share on other sites

  • 2 weeks later...

Re: 1h work to solve the dumbest error there is

$query = sprintf("SELECT rank,prize FROM prizes WHERE type = 'supporter'");

change to

$query = sprintf("SELECT rank,prize FROM prizes WHERE type=supporter")

AND

$prizeResult = mysql_query($query);

change to

$prizeResult = mysql_query($query) or die(mysql_error());

 

That will tell you exactly what is wrong with the query. It was made for a reason, to make debugging faster.

Link to comment
Share on other sites

  • 7 months later...

Re: 1h work to solve the dumbest error there is

 

$res = mysql_query("SELECT * FROM village");

if ($res) {
while ($newarray = mysql_fetch_array($res, mysql_assoc)) {
	$id = $newarray['id'];
	$vname = $newarray['name'];
	$vplayer = $newarray['player'];
	echo "the id of the village is ".$id." its name is ".$vname." the owner is ".$vplayer."
";
}
} else {
printf("failed: %s\n", mysql_error($mysql));
}

 

this isn't a script of mine but we have looked 1h to find the error in this small script, the error is the famous Warning: mysql_fetch_array missing argument thingy

the solution is actually very simple (deception already knows so refrain from posting please) so lets see who can find it faster than we did

Is it this

printf("failed: %s\n", mysql_error($mysql));

but it should be

print("failed: %s\n", mysql_error($mysql));

????

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...