Page 1 of 1

php+mysql

Posted: Sat Mar 26, 2011 8:20 pm
by mastersan
Hi can some on tell where i am wrong

Code: Select all

<?php
$db = mysql_connect(' ****** ',' ****** ',' ****** ') or die();
mysql_select_db(' ****** ', $db);
$result = mysql_query("set names 'utf8'");
$query = "select * from table ORDER BY id";
$result = mysql_query($query);
$userrow = mysql_fetch_array( $result );

while($userrow = mysql_fetch_array($result)){
	echo $userrow['id']. " - ". $userrow['username']. " - ". $userrow['currenthp']. " - ". $userrow['maxhp']. " - ". $userrow['gold'];
	echo "<br />";


		if($userrow["currenthp"] != ($userrow["maxhp"])){
	
		 	$result2 =mysql_query("UPDATE table SET `currenthp` = `currenthp` + '1' 
			WHERE `id` = '".$userrow["id"]."'", "users");
			
			}
			else {
			echo "NEW HP-";
			echo $userrow['id']. " - ". $userrow['username']. " - ". $userrow['currenthp']. " - ". $userrow['maxhp']. " - ". $userrow['gold'];
			echo "<br />";
			}

}
?>
and error is
Parse error: syntax error, unexpected ',' in /home/****.php on line 16
can tell any one where i am wrong
o and yes i am new in programming so don't bee ruff :)

Re: php+mysql

Posted: Sat Mar 26, 2011 8:29 pm
by MindOverBody
In your UPDATE query, at the end "users" is not needed... whatever it is.
mysql_query() function takes only two parameters, first is query string, and second is connection identifier which can not be string value.
Second parameter is optional. But, if you want to use connection identifier, put $db instead of "users".
Check mysql_query() function manual.

Cheers!

Re: php+mysql

Posted: Sat Mar 26, 2011 8:34 pm
by mastersan
Thank you very much