6 Replies - 3840 Views - Last Post: 08 May 2009 - 07:02 AM Rate Topic: -----

#1 kcvontop  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-April 09

my WAMP server cannot process this login script, can somebody help ide

Posted 07 May 2009 - 08:20 AM

HELLO house! :rolleyes:

I suppose this script should work but it's not and i can't seem to identify the problem. it appears my wamp server cannot retrieve values from the $db_name and $table_name variables. when i make the post it reffers me back to
the login page i.e show_login.html without making any attempt to execute the php script. Please i need help.

<?php
//check for required fields
if ((!$_POST[username]) || (!$_POST[password])) {
header( "Location: show_login.html");
exit;
}

//set up names of database and table to use
$db_name = "loglist";
$table_name = "auth_users";


//connect to server and select database
$connection = @mysql_connect("localhost", "root")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());


//build and issue the query
$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]'
AND password = password('$_POST[password]')";
$result = @mysql_query($sql,$connection) or die(mysql_error());


//get the number of rows in the result set
$num = mysql_num_rows($result);


//print a message or redirect elsewhere, based on result
if ($num != 0) {
$msg = "<P>Congratulations, you're authorized!</p>";
} else {
header("Location: show_login.html");
exit;
}
?>


<HTML>
<HEAD>
<TITLE>Secret Area</TITLE>
</HEAD>
<BODY>
<?php echo "$msg"; ?>
</BODY>
</HTML>


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 07 May 2009 - 08:39 AM


Is This A Good Question/Topic? 0
  • +

Replies To: my WAMP server cannot process this login script, can somebody help ide

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3075
  • Posts: 10,784
  • Joined: 08-August 08

Re: my WAMP server cannot process this login script, can somebody help ide

Posted 07 May 2009 - 08:29 AM

This will always be false:
if ((!$_POST[username]) || (!$_POST[password])) {


because there is never a $_POST[anything]. It needs to be $_POST['anything']. Try it this way:
if ((!$_POST['username']) || (!$_POST['password'])) {

Was This Post Helpful? 0
  • +
  • -

#3 kcvontop  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-April 09

Re: my WAMP server cannot process this login script, can somebody help ide

Posted 07 May 2009 - 04:55 PM

Thank u so much for your prompt response. But I tried what you said, it still didn't work.Maybe you should try and run the script yourself and detect the problem.



View PostCTphpnwb, on 7 May, 2009 - 07:29 AM, said:

This will always be false:
if ((!$_POST[username]) || (!$_POST[password])) {


because there is never a $_POST[anything]. It needs to be $_POST['anything']. Try it this way:
if ((!$_POST['username']) || (!$_POST['password'])) {

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3075
  • Posts: 10,784
  • Joined: 08-August 08

Re: my WAMP server cannot process this login script, can somebody help ide

Posted 07 May 2009 - 05:18 PM

I can't duplicate your system: I don't have your database. Maybe you should describe the problem in some detail.
Was This Post Helpful? 0
  • +
  • -

#5 kcvontop  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-April 09

Re: my WAMP server cannot process this login script, can somebody help ide

Posted 08 May 2009 - 01:29 AM

Thank u friend i can't appreciate u enough for your attention.

As u said i will explain in detail. To start with, i run a WAMP server 2.0 on my system with the following versions: php 5.2.7, mysql 5.1.30, apache 2.2.10.

I saw the login script in a text book on php6. I set up a database name loglist and a table name auth_users with two columns username and password with a value for username and password on mysql server. below is the html login page according to the textbook

<HTML>
<HEAD>
<TITLE>Login</TITLE>
</HEAD>
<BODY>
<H1>Login to Secret Area</H1>
<FORM METHOD="POST" ACTION="do_authuser.php">
<P><STRONG>Username:</STRONG><BR>
<INPUT TYPE="text" NAME="user" SIZE=25 MAXLENGTH=25></p>
<P><STRONG>Password:</STRONG><BR>
<INPUT TYPE="password" NAME="pass" SIZE=25 MAXLENGTH=25></p>
<P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login"></P>
</FORM>
</BODY>
</HTML>

AND AGAIN BELOW IS THE DO_AUTHUSERS.PHP SCRIPT

<?
//check for required fields
if ((!$_POST[username]) || (!$_POST[password])) {
header( "Location: show_login.html");
exit;
}
//set up names of database and table to use
$db_name = "loglist";
$table_name = "auth_users";
//connect to server and select database
$connection = @mysql_connect("localhost", "spike", "9sj7En4")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
//build and issue the query
$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]'
AND password = password('$_POST[password]')";
$result = @mysql_query($sql,$connection) or die(mysql_error());
//get the number of rows in the result set
$num = mysql_num_rows($result);
//print a message or redirect elsewhere, based on result
if ($num != 0) {
$msg = "<P>Congratulations, you're authorized!</p>";
} else {
header("Location: show_login.html");
exit;
}
?>
<HTML>
<HEAD>
<TITLE>Secret Area</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>

when i enter values into the form field it refers me back to show_login.html. which means it execution stops at

if ((!$_POST[username]) || (!$_POST[password])) {
header( "Location: show_login.html");
exit;
}

at least i thought so. You said i should change if ((!$_POST[username]) || (!$_POST[password])) to

if ((!$_POST['username']) || (!$_POST['password'])) which i did but still get the same result.


I was thinking if there are new syntax changes in php 6 which may not be compatible with my php5.2.7.

please can u go through the script again and help me figure out where the problem might be.



View PostCTphpnwb, on 7 May, 2009 - 04:18 PM, said:

I can't duplicate your system: I don't have your database. Maybe you should describe the problem in some detail.

Was This Post Helpful? 0
  • +
  • -

#6 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: my WAMP server cannot process this login script, can somebody help ide

Posted 08 May 2009 - 02:38 AM

You should use:
if ((!$_POST['user']) || (!$_POST['pass'])) 

since you've named your input fields to "user" and "pass"! :) Try it again with that simple fix and it should work unless there any more bugs!

Hope it helps! :)

Btw, please lowercase your HTML code! *Gaaah, going crazy* :crazy:

View Postkcvontop, on 8 May, 2009 - 12:29 AM, said:

Thank u friend i can't appreciate u enough for your attention.

As u said i will explain in detail. To start with, i run a WAMP server 2.0 on my system with the following versions: php 5.2.7, mysql 5.1.30, apache 2.2.10.

I saw the login script in a text book on php6. I set up a database name loglist and a table name auth_users with two columns username and password with a value for username and password on mysql server. below is the html login page according to the textbook

<HTML>
<HEAD>
<TITLE>Login</TITLE>
</HEAD>
<BODY>
<H1>Login to Secret Area</H1>
<FORM METHOD="POST" ACTION="do_authuser.php">
<P><STRONG>Username:</STRONG><BR>
<INPUT TYPE="text" NAME="user" SIZE=25 MAXLENGTH=25></p>
<P><STRONG>Password:</STRONG><BR>
<INPUT TYPE="password" NAME="pass" SIZE=25 MAXLENGTH=25></p>
<P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login"></P>
</FORM>
</BODY>
</HTML>

AND AGAIN BELOW IS THE DO_AUTHUSERS.PHP SCRIPT

<?
//check for required fields
if ((!$_POST[username]) || (!$_POST[password])) {
header( "Location: show_login.html");
exit;
}
//set up names of database and table to use
$db_name = "loglist";
$table_name = "auth_users";
//connect to server and select database
$connection = @mysql_connect("localhost", "spike", "9sj7En4")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
//build and issue the query
$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]'
AND password = password('$_POST[password]')";
$result = @mysql_query($sql,$connection) or die(mysql_error());
//get the number of rows in the result set
$num = mysql_num_rows($result);
//print a message or redirect elsewhere, based on result
if ($num != 0) {
$msg = "<P>Congratulations, you're authorized!</p>";
} else {
header("Location: show_login.html");
exit;
}
?>
<HTML>
<HEAD>
<TITLE>Secret Area</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>

when i enter values into the form field it refers me back to show_login.html. which means it execution stops at

if ((!$_POST[username]) || (!$_POST[password])) {
header( "Location: show_login.html");
exit;
}

at least i thought so. You said i should change if ((!$_POST[username]) || (!$_POST[password])) to

if ((!$_POST['username']) || (!$_POST['password'])) which i did but still get the same result.


I was thinking if there are new syntax changes in php 6 which may not be compatible with my php5.2.7.

please can u go through the script again and help me figure out where the problem might be.



View PostCTphpnwb, on 7 May, 2009 - 04:18 PM, said:

I can't duplicate your system: I don't have your database. Maybe you should describe the problem in some detail.

Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3075
  • Posts: 10,784
  • Joined: 08-August 08

Re: my WAMP server cannot process this login script, can somebody help ide

Posted 08 May 2009 - 07:02 AM

Also, please put your code inside [ code ] [ /code ] tags!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1