Page 1 of 3

some help please!! Warning: mysql_fetch_array(): suppl

Posted: Wed Jul 26, 2006 12:25 pm
by dandare
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


OK

I am quite new to all this php/MySql stuff, though I feel I have managed well up until this point.

I keep receiving: "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in...."

and I do not know how to solve the problem.

What I am trying to create is a simple login page.

I have ruled out the possiblility of the query not being recognised in MySql by running the line through MySQL itself.

I've put a few line breaks in so you can spot the problematic code 

Ladies and gentlemen, i present to you the problem   ....

Code: Select all

<?php
if(isset($_POST['submit'])) {
require_once('../conn.php');
function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
}
$message = NULL;
//check userName
if (empty($_POST['username'])) {
$un = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
}else{
$un = escape_data($_POST['username']);
}
//Check password
if (empty($_POST['password'])) {
$pw = FALSE;
$message .= ' <p>You forgot to enter your password!</p>';
}else{
$pw = escape_data($_POST['password']);
}
if ($un && $pw) {


$sql = "SELECT userID FROM tblRegister WHERE userName='$un' AND password=PASSWORD('$pw')";
$result = mysql_query ($sql);
$row = mysql_fetch_array ($result);



if ($row) {
session_name('Your visit ID');
session_set_cookie_params (900, 'modulecb154.php');
session_start();
$_SESSION['userID'] = $row[1];
header ("Location: http//" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) .
"/cb154.php");
exit();
}else{
$message = '<p>Your username/password is incorrect.</p>';
}
mysql_close();
}else{
$mesage .= '<p>Pleas try again.</p>';
}
}
$page_title = 'login.php';
include('header.inc');
if (isset($message)) {
echo '<font color = "red">' , $message, '</font>';
}
?>

<div id="login"> 
  <form method="post" action"login.php">
    <h1>Login</h1>
    <span class="formstyle">Username</span> 
    <input type="text" name="username" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>" />
    <br>
    <br>
    <span class="formstyle">Password</span>&nbsp;
    <input type="password" name="password" />
	<br><Br>
	<input type="submit" name="submit" value="LOGIN" class="button"/></span>
  </form>
</div>
<div id="regmenu"><table width="200" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td><a href="register.php">Register</a></td>
    <td><a href="passwordreminder.php">Forgot Password</a></td>
  </tr>
</table>
</div>
<?php
include ('footer.inc');
?>

Look forward to the answer!!! :)


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jul 26, 2006 12:31 pm
by daedalus__
You probably have an error in your SQL, add an "or die(mysql_error())" or an "or print(mysql_error())" to the query.

Posted: Wed Jul 26, 2006 12:34 pm
by kbrown3074
I see its possible to set $un = FALSE and then putting it into the sql statement. If $un does equal false..that could be where your sql statement is bombing out. Does it happen everytime you dont have a value for username? I would set $un = '' instead.

Posted: Wed Jul 26, 2006 12:34 pm
by RobertGonzalez
dandare, the error message comes from trying to pass a mysql query result resource to the fetch call. You need some error checking in your code to verify that your queries are working properly in your code.

Posted: Wed Jul 26, 2006 12:47 pm
by dandare
Daedalus

I entered 'or die....'

It came back with Error connecting to mySql

Posted: Wed Jul 26, 2006 12:55 pm
by daedalus__
You should check the connection info you pass to mysql_connect().

Posted: Wed Jul 26, 2006 12:57 pm
by dandare
happens all the time kbrown.

So there is an error connecting, it seems. I have checked the conn.php file which seems to be ok. No error such as not recognising the name, username or password of the database itself.

:?

Can't think what else to try. Obivously it would not allow me to retrieve data from the database itself.
Is there any code i can use to distinguish where it all goes wrong?

Posted: Wed Jul 26, 2006 1:02 pm
by RobertGonzalez
Cannot connect means that your credentials are not making it past the point of opening the DB connection socket. You have not DB connection.

Posted: Wed Jul 26, 2006 1:08 pm
by jamiel
In your conn.php when you do your connect, add an or die(mysql_error()); after the mysql_connect . Show us the exact error if you can't figure out whats wrong.

conn.php

Posted: Wed Jul 26, 2006 1:15 pm
by dandare

Code: Select all

<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pasword';

$dbc = mysql_connect($dbhost, $dbuser, $dbpass) or die 
 mysql_error();

$dbname = 'mechacol_UEL';
mysql_select_db($dbname);
?>
That's the code that connects...
anything wrong there? :?

Posted: Wed Jul 26, 2006 1:34 pm
by RobertGonzalez
Try this in it's own PHP page and report back what is echoed...

Code: Select all

<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pasword';

if (!$dbc = mysql_connect($dbhost, $dbuser, $dbpass))
{
    die('Could not establish a connection: ' . mysql_error());
}
else
{
    echo '<p>We are in!</p>';
}

$dbname = 'mechacol_UEL';
if (!mysql_select_db($dbname))
{
    die('Could not get the database: ' . mysql_error());
}
else
{
    echo '<p>We have a DB too!</p>';
}
?>

Posted: Wed Jul 26, 2006 1:43 pm
by dandare
Warning: mysql_connect(): Access denied for user 'user'@'localhost' (using password: YES) in xxxx/test.php on line 6
Could not establish a connection: Access denied for user 'user'@'localhost' (using password: YES)

Posted: Wed Jul 26, 2006 1:45 pm
by RobertGonzalez
Cool, that is actually helpful.

What MySQL server version are you running and what is your MySQL Client API version? The MySQL version can be found in phpMyAdmin or by running this query:

Code: Select all

SELECT VERSION();
The MySQL Client API version can be found in your phpinfo() output.

Posted: Wed Jul 26, 2006 1:45 pm
by daedalus__
Are you actually trying to log-in with "user" and "password". I'm going to say that those are probably the wrong credentials.

Posted: Wed Jul 26, 2006 1:49 pm
by Benjamin
It isn't an old password issue. Either the privileges need to be flushed, or the credentials are wrong.