Jump to content

Help, getting error; Warning: mysql_fetch_array():


atrum

Recommended Posts

Hello all,

 

I am trying to teach my self php cookies, and php mysql authentication and I am not having much luck with it.

 

When I submit my information on <http://tools.exiled-alliance.com/testsite/index.php>, The following Error is printed to the screen.

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/cdorris/www/tools.exiled-alliance.com/testsite/home.php on line 16
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Select * FROM tbl_auth_user WHERE user_id='tools'' at line 1

 

 

Here is the login script:

 

 

<?php
ini_set('display_errors','On');

include("constr.php");
$passwordHash = sha1($_POST['password']);

mysql_select_db("tools", $sqlcon);
$user ="$_POST[username]";
$sqlu ="SELECT * FROM tbl_auth_user WHERE user_id ='$user'" ;

if (!mysql_query($sqlu,$sqlcon))

{
	die('Error:' . mysql_error());

}
else
$row = mysql_fetch_array($sqlu);
if(!$row['user_password'] = $passwordHash)
{

	die('incorrect user name and or password' . mysql_error());
}
mysql_close($sqlcon);

include("setcookie.php");


header( 'Location: http://tools.exiled-alliance.com/testsite/home.php' ) ;

?>

 

 

Here is the setcookie.php:

 

 

<?php
include("constr.php");

mysql_select_db("tools", $sqlcon);
$user = $_POST['username'];

$sqlu ="Select * FROM tbl_auth_user WHERE user_id='$user'";
setcookie("COOKIE:testsite", "$sqlu", time()+1500);
?>

 

Here is the home.php page which the login script is set to redirect to.

 

<?php
ini_set('display_errors','On');

include("constr.php");
mysql_select_db("tools", $sqlcon);
//$user1 = $_COOKIE["COOKIE:testsite"];
//$sqlu ="SELECT * FROM tbl_auth_user WHERE user_id ='$user'";
$sqlu ="SELECT * FROM tbl_auth_user WHERE user_id =" . $_COOKIE["COOKIE:testsite"] . "";
if (mysql_query($sqlu,$sqlcon))

{
die('Error:' . mysql_error());

}

while($row1 = mysql_fetch_array($sqlu))
{
	echo $row1['firstName'];

}
echo mysql_error();
?>

 

Steps to recreate issue:

1. browse to [http://tools.exiled-alliance.com/testsite/index.php]

2. login with. User: testuser, Pass:password

 

I am honestly at wits end with this one, so any help you can provide would be greatly appreciated.

Also I believe that in setcookie.php

 

setcookie("COOKIE:testsite", "$sqlu", time()+1500);

should be

setcookie("COOKIE:testsite", "$user", time()+1500);

 

and in login script

 

$sqlu ="SELECT * FROM tbl_auth_user WHERE user_id =" . $_COOKIE["COOKIE:testsite"] . "";

should  be

$sqlu ="SELECT * FROM tbl_auth_user WHERE user_id ='{$_COOKIE["COOKIE:testsite"]}'";

Hey guys, thanks alot for the help.

 

I think I need to split the different functions up, like the login, the session, and the mysql connection before I try to combine them.

 

The script seems to always fail on the sql results portion under mysql_fetch_array.

 

Does anyone have any suggestions on reading material for what I am trying to accomplish?

Archived

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

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