Current location: Hot Scripts Forums » Programming Languages » PHP » Problem with: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result


Problem with: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result

Reply
  #1 (permalink)  
Old 07-28-09, 05:21 PM
mysqlhelp's Avatar
mysqlhelp mysqlhelp is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Problem with: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result

IM just trying my Online-Game, and when i try to log in, it says this error:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/duchazer/public_html/JuegoSD/modulos/prelogin.php on line 4

rune99wiki.pcriot.com/JuegoSD/

Prelogin.php:
Code:
<?php
	if (isset($_POST['usuario'])){   //Comprueba si hay info para login
		$info=obtener_usuario($_POST[usuario], $_POST[pass]); //Comprueba si existe usuario y clave
		$datos=mysqli_fetch_assoc($info); //convierte el sql en array
		if(count($datos)==0){ //coteja si la contraseña es válida
		  $registrado=1;
    }else{
			$_SESSION['id_usuario']=$datos['id'];
			$_SESSION['nick_usuario']=$datos['nick'];
			echo '
       <script type="text/javascript">
        redireccionar();
       </script>';
			}
		}
?>
Reply With Quote
  #2 (permalink)  
Old 07-28-09, 06:04 PM
mysqlhelp's Avatar
mysqlhelp mysqlhelp is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
And if you need to know what PHP and MYSQL Versions i use, this are:

PHP VERSION: 5.2.8 Version 1 - Basic
MYSQL VERSION: 5.0.81-community
Reply With Quote
  #3 (permalink)  
Old 07-28-09, 06:10 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
The MySQLi functions don't work the same as the MySQL functions.

Here's how it should look like: PHP: mysqli_result::fetch_assoc - Manual
Reply With Quote
  #4 (permalink)  
Old 07-28-09, 06:27 PM
mysqlhelp's Avatar
mysqlhelp mysqlhelp is offline
New Member
 
Join Date: Jul 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, i try this:

Quote:
<?php
if (isset($_POST['usuario'])){ //Comprueba si hay info para login
$info=obtener_usuario($_POST[usuario], $_POST[pass]); //Comprueba si existe usuario y clave
$datos=mysqli_result::fetch_assoc($info); //convierte el sql en array
if(count($datos)==0){ //coteja si la contraseña es válida
$registrado=1;
}else{
$_SESSION['id_usuario']=$datos['id'];
$_SESSION['nick_usuario']=$datos['nick'];
echo '
<script type="text/javascript">
redireccionar();
</script>';
}
}
?>
And this appear:

Fatal error: Non-static method mysqli_result::fetch_assoc() cannot be called statically in /home/duchazer/public_html/JuegoSD/modulos/prelogin.php on line 4

Then i try this:

Quote:
<?php
if (isset($_POST['usuario'])){ //Comprueba si hay info para login
$info=obtener_usuario($_POST[usuario], $_POST[pass]); //Comprueba si existe usuario y clave
$datos=mysqli_fetch_assoc(mysqli_result $info); //convierte el sql en array
if(count($datos)==0){ //coteja si la contraseña es válida
$registrado=1;
}else{
$_SESSION['id_usuario']=$datos['id'];
$_SESSION['nick_usuario']=$datos['nick'];
echo '
<script type="text/javascript">
redireccionar();
</script>';
}
}
?>
And this appear:

Parse error: syntax error, unexpected T_VARIABLE in /home/duchazer/public_html/JuegoSD/modulos/prelogin.php on line 4

And finally, i try changing ($info) to ($result):

Quote:
<?php
if (isset($_POST['usuario'])){ //Comprueba si hay info para login
$info=obtener_usuario($_POST[usuario], $_POST[pass]); //Comprueba si existe usuario y clave
$datos=mysqli_fetch_assoc($result); //convierte el sql en array
if(count($datos)==0){ //coteja si la contraseña es válida
$registrado=1;
}else{
$_SESSION['id_usuario']=$datos['id'];
$_SESSION['nick_usuario']=$datos['nick'];
echo '
<script type="text/javascript">
redireccionar();
</script>';
}
}
?>
And this appear:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in /home/duchazer/public_html/JuegoSD/modulos/prelogin.php on line 4

Last edited by mysqlhelp; 07-28-09 at 06:31 PM.
Reply With Quote
  #5 (permalink)  
Old 07-29-09, 02:02 AM
noorahmad noorahmad is offline
New Member
 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ok try this:
Where $con is your connection to mysql using mysqli_connect() function, and tblusers is your users table in your database.
Code:
<?php
	if (isset($_POST['usuario'])){   //Comprueba si hay info para login
		$un = $_POST['usuario'];
		$pa =  $_POST['pass']; //Comprueba si existe usuario y clave
		$info = mysqli_query($con,"select * from tblusers where username='$un' and password='$pa'")or die(mysqli_error($con));;
		$datos=mysqli_fetch_assoc($info); //convierte el sql en array
		if(count($datos)==0){ //coteja si la contraseña es válida
		  $registrado=1;
    }else{
			$_SESSION['id_usuario']=$datos['id'];
			$_SESSION['nick_usuario']=$datos['nick'];
			echo '
       <script type="text/javascript">
        redireccionar();
       </script>';
			}
		}
?>
Reply With Quote
  #6 (permalink)  
Old 07-29-09, 02:03 AM
noorahmad noorahmad is offline
New Member
 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
?

ok try this:
Where $con is your connection to mysql using mysqli_connect() function, and tblusers is your users table in your database.
Code:
<?php
	if (isset($_POST['usuario'])){   //Comprueba si hay info para login
		$un = $_POST['usuario'];
		$pa =  $_POST['pass']; //Comprueba si existe usuario y clave
		$info = mysqli_query($con,"select * from tblusers where username='$un' and password='$pa'")or die(mysqli_error($con));;
		$datos=mysqli_fetch_assoc($info); //convierte el sql en array
		if(count($datos)==0){ //coteja si la contraseña es válida
		  $registrado=1;
    }else{
			$_SESSION['id_usuario']=$datos['id'];
			$_SESSION['nick_usuario']=$datos['nick'];
			echo '
       <script type="text/javascript">
        redireccionar();
       </script>';
			}
		}
?>
Reply With Quote
Reply

Bookmarks

Tags
mysql, mysql problems, mysqli, problem


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unknown Javascript/Ajax problem vitron JavaScript 9 06-05-09 11:44 AM
mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, ausgezeichnete PHP 3 10-27-07 08:09 AM
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 05:18 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM


All times are GMT -5. The time now is 07:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.