/    Sign up×
Community /Pin to ProfileBookmark

simple parse error but i cant debug it

I keep getting a parse error on the following line:

[code=php]while($row = mysql_fetch_array[‘result’])[/code]

I downloaded the script (i cant remember where from now) but I have been trying to alter to to get it to work, but I’m not the usuage of

[code=php]mysql_fetch_array[‘result’][/code]

like that before

[code=php]

<?

include”settings.php”;

if (isset($submit)) // name of submit button
{ $query = “select * from logintable where username=’$username’ and password=’$password'”;
echo “nnQuery:”.$query;

$result = mysql_query($query);
echo “nnResult:”.$result;
$isAuth = false; //set to false originally

while($row = mysql_fetch_array[‘result’])
{
echo $row[‘username’];
echo $row[‘password’];
if($row[‘username’] == $username)
//above row checks to see if username/password combination exists
{
$isAuth = true;
session_start();
session_register(‘username’);
}
}
if($isAuth)
{
print “logged in successfully<br>”;
print “<A href=’index.php’>Go to Admin Panel</a>”;
}
else
//if login/pass does not exist
{
print “Wrong username or password”;
}
}
?>[/code]

Or if anyone can direct me to simple easy to use login script for admin system it would be greatly appreciated,

thanks Neil

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@solavarMay 17.2004 — mysql_fetch_array is a function.

So...

[code=php]
mysql_fetch_array['result'];

is wrong. It implies that mysql_fetch_array is an array not a function.
[/code]


... it must be

[code=php]
mysql_fetch_array($result);

a function uses round brackets, not square ones.

[/code]
Copy linkTweet thisAlerts:
@neilauthorMay 17.2004 — thats what i thought about the function,

but i got confused as to whether it was right or not because when i change it to
[code=php]while($row = mysql_fetch_array($result))[/code]

i get the following error messages

form submitted Query:select * from logintable where username='username' and password='password' [COLOR=red]Warning: Access denied for user: 'urbanaca@localhost' (Using password: NO) in /home/urbanaca/public_html/test/authenticate.php on line 21 Warning: MySQL Connection Failed: Access denied for user: 'urbanaca@localhost' (Using password: NO) in /home/urbanaca/public_html/test/authenticate.php on line 21 Warning: MySQL: A link to the server could not be established in /home/urbanaca/public_html/test/authenticate.php on line 21 [/COLOR] Result: [COLOR=red]Warning: Supplied argument is not a valid MySQL result resource in /home/urbanaca/public_html/test/authenticate.php on line 25[/COLOR] Wrong username or password
Copy linkTweet thisAlerts:
@solavarMay 17.2004 — Check the connection string in your settings.php, ie username and password to connect to the database.
Copy linkTweet thisAlerts:
@neilauthorMay 17.2004 — i'm trying that,

but unless I'm mistaken the correct name/pass are not working? ??
Copy linkTweet thisAlerts:
@neilauthorMay 17.2004 — I've used some different connection code from another file i had work and I don't get the errors now, but i've got a different problem which i will post if it continues to prove a problem
Copy linkTweet thisAlerts:
@neilauthorMay 17.2004 — the code is now like this

The connection info is all correct, when i test the sql in php admin it is fine,

but i think it gives false for while($row = mysql_fetch_array($result))

doesn't go into the while loop and goes straight into print "Wrong username or password"; because $auth is false

any idead anyone?

Cheers Neil


[code=php]

<?

# PULL ADDITIONAL FILES
include_once (".././settings.php");
# CONNECT TO THE MySQL SERVER
$link = mysql_connect($host,$user,$password);
# SELECT THE DATABASE NEEDED
mysql_select_db("$base");


if (isset($submit)) // name of submit button
{
echo "form submittednn";
$query = "select * from logintable where username='$username' and password='$password'";
echo "ttQuery:".$query;
// $db = mysql_pconnect($dbHost, $dbUser, $dbPass);
// mysql_select_db($dbName, $db);
$result = mysql_query($query);
//echo "ttResult:".$result;
$isAuth = false; //set to false originally

while($row = mysql_fetch_array($result))
{
//echo $row['username'];
//echo $row['password'];
if($row['username'] == $username)
//above row checks to see if username/password combination exists
{
$isAuth = true;
session_start();
session_register('username');
}
}
if($isAuth)
{
print "logged in successfully<br>";
print "<A href='index.php'>Go to Admin Panel</a>";
}
else
//if login/pass does not exist
{
print "Wrong username or password";
}
}
?>[/code]
Copy linkTweet thisAlerts:
@neilauthorMay 18.2004 — I just realised an include used a same variable name as one submitted by the form

but with having this before echoes causes the error "msg headers already sent" , any ideas whats that about?

session_start();
×

Success!

Help @neil spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...