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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

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

Post 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]
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post 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.
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

Post by dandare »

Daedalus

I entered 'or die....'

It came back with Error connecting to mySql
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

You should check the connection info you pass to mysql_connect().
dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post 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.
dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

conn.php

Post 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? :?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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>';
}
?>
dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

Post 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)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

It isn't an old password issue. Either the privileges need to be flushed, or the credentials are wrong.
Post Reply