Jump to content

Mysql Result Warnings


Utherr12

Recommended Posts

I made an account creation form with username mail and password. The form works and the php code too because i see the entries in my sql db... BUT it gives me warnings:Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in D:\webserver\functions.php on line 9 Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 6 in D:\webserver\functions.php on line 10 .create_acc.php :

<?phpini_set('display_errors', 1);error_reporting(E_ALL);include("functions.php");$valid = create_acc(strtolower($_POST['Username']),$_POST['pass'],strtolower($_POST['Email']));if ($valid)	{echo "<p>Account succesfully created</p><br />";}	else	{echo "<p>Account name or Email already exists</p><br />";}?>

functions.php:

<?phpfunction create_acc($username,$password,$mail){	$phpDB = mysql_connect("ip","xxxx","xxx");	mysql_select_db("php",$phpDB);		$username_array = mysql_query("SELECT `name` FROM `test_table` WHERE `name` = '$username';",$phpDB);	$mail_array = mysql_query("SELECT `mail` FROM `test_table` WHERE `mail` = '$mail';",$phpDB);		$username_db = mysql_result($username_array,0);	$mail_db = mysql_result($mail_array,0);		if(($username_db!=$username)&&($mail_db!=$mail))	{		$date_joined = date("d/m/Y H:i:s");		$password_hash = hash('md5',$password,false);				$createAcc = mysql_query("INSERT INTO `test_table` (`name`,`mail`,`pw_hash`,`date_joined`) VALUES ('$username','$mail','$password_hash','$date_joined');",$phpDB);		return 1; // 1 == Success	  }		else return 0; // 0 == failed	mysql_close($phpDB);}?>

Even though account creation works, i'm getting those two Warnings. I didn't had any problems with this before i decided to integrate this into a function on a separate file.My sql db had only 1 entry before i created the account with 0's on every column for testing.I'm mentioning that those warnings only appear when account doesn't yet exist in DB ... if i try to make a duplicate account, no warning appears and the function returns 0.

Link to comment
Share on other sites

You're not checking if the query returned records, you're just assuming there's one there.

$result = mysql_query("SELECT `name` FROM `test_table` WHERE `name` = '$username';",$phpDB) or exit(mysql_error($phpDB);if ($row = mysql_fetch_assoc($result)){  // existing username found  $name = $row['name'];}else{  // existing username not found}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...