/    Sign up×
Community /Pin to ProfileBookmark

noob need help

<HTML>

<BODY>
<?
// Login.php
include(“DBPARAM.php”);

// connect to database
mysql_connect($hostname,$userName,$password) or die(“Error connecting to MySQL Server”);

mysql_select_db($database) or die(“Error selecting database”);

// get data from FORM – Login.html
$usrName = $_REQUEST[“txtusername”];

$usrPassword = $_REQUEST[“txtPassword”];

$sql = “SELECT * FROM STAFF_PWD WHERE staff_id=’$usrName’ AND staff_pwd=’$usrPassword'”;

// execute the SQL statement and get the result
$result = mysql_db_query($database,$sql) or die(“Error running SQL”);

// calculate number of records (row)
$row = mysql_num_rows($result);

?>

<?

if ( $row <= 0 ) { ?>

<p><font face=”Arial” color=”#FF0000″>Invalid username and/or password.</font></p>
<p><font face=”Arial” color=”#FF0000″><a href=”Login.html”>Please click here to
try again.</a></font></p>
<? }
else
{
header(“Location:Filename.html”);
}
?>

<? mysql_close(); ?>
</BODY>

</HTML>

//————

i am getting a blank page if i execute the login page. is there anything wrong with my coding??

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 14.2006 — You can't use the header() function if any character has been outputted, which is the case here
Copy linkTweet thisAlerts:
@dirtauthorMar 15.2006 — so how would i get myself to the next page if i don't have header() ??
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 15.2006 — You would have to do the whole processing before outputting any character to the screen, and in case of an error (e.g.: no rows returned) you can output something
Copy linkTweet thisAlerts:
@acemoMar 15.2006 — try this
[code=php]
<?
// Login.php
include("DBPARAM.php");

// connect to database
mysql_connect($hostname,$userName,$password) or die("Error connecting to MySQL Server");

mysql_select_db($database) or die("Error selecting database");

// get data from FORM - Login.html
$usrName = $_REQUEST["txtusername"];
$usrPassword = $_REQUEST["txtPassword"];

$sql = "SELECT * FROM STAFF_PWD WHERE staff_id='$usrName' AND staff_pwd='$usrPassword'";

// execute the SQL statement and get the result
$result = mysql_db_query($database,$sql) or die("Error running SQL");

// calculate number of records (row)
$row = mysql_num_rows($result);
?>

<?
if ( $row <= 0 ) { ?>
<HTML>

<BODY>

<p><font face="Arial" color="#FF0000">Invalid username and/or password.</font></p>
<p><font face="Arial" color="#FF0000"><a href="Login.html">Please click here to
try again.</a></font></p>
</BODY>

</HTML>
<? }
else
{
header("Location: Filename.html");
}
mysql_close(); ?>
[/code]
Copy linkTweet thisAlerts:
@dirtauthorMar 15.2006 — Thanks for the help. but i am still getting the blank page.

when i execute some other .php codes it works and some dont they go to

blank page.

thanks...
Copy linkTweet thisAlerts:
@chazzyMar 15.2006 — just a hunch, does DBPARAM.php contain any errors that you might have overlooked?

Also, I don't like this line, it's deprecated for one thing:

[code=php]
$result = mysql_db_query($database,$sql) or die("Error running SQL");
[/code]


replace it with:
[code=php]
$result = mysql_query($sql) or die("Error running query string: ".mysql_error());
[/code]
Copy linkTweet thisAlerts:
@dirtauthorMar 16.2006 — <?

// DBPARAM.php

$hostname = "localhost";
$userName = "username";
$password = "password";
$database = "databasename";

?>

when i insert the correct value for the username and password. i get stuck with a blank page with http://localhost/login.php page. not going to the place i specified. if its a wrong value it works, it goes to the error page.
Copy linkTweet thisAlerts:
@acemoMar 16.2006 — the blank page probably is a result of a warning/notice and warnings/notices not being shown by your server.

put this on top of all pages that are involved in this application.

error_reporting(E_ALL);

it should give u some warning/notice on the blank page then
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — try this:

[code=php]
<?php
# report all errors
error_reporting(E_ALL);
// Login.php
include("DBPARAM.php");

// connect to database
mysql_connect($hostname,$userName,$password) or die("Error connecting to MySQL Server");

mysql_select_db($database) or die("Error selecting database");

// get data from FORM - Login.html
$usrName = $_REQUEST["txtusername"];
$usrPassword = $_REQUEST["txtPassword"];

$sql = "SELECT * FROM STAFF_PWD WHERE staff_id='$usrName' AND staff_pwd='$usrPassword'";

// execute the SQL statement and get the result
$result = mysql_query($sql) or die("Error running query string: ".mysql_error());

// calculate number of records (row)
$row = mysql_num_rows($result);

mysql_close();

if($row == 1){
# OK
header("Location: Filename.html");
}else{
# user/password combination does not exist

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Error: invalid username and/or password!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
p.error{
font-family: Arial, serif;
color: #ff0000;
}
</style>
</head>
<body>
<h1>Error</h1>
<p class="error">Invalid username and/or password.</p>
<p><a href="Login.html">Please click here to try again.</p>
</body>
</html>
<?php
}
?>
[/code]
Copy linkTweet thisAlerts:
@bokehMar 16.2006 — put this on top of all pages that are involved in this application.

error_reporting(E_ALL);[/QUOTE]
If [I]display_errors[/I] is turned off that line will do nothing... And if the error is a parse error in the script that line will not even be read runtime.

If you are not in control of the server it is possible to add error reporting in [I].htaccess[/I]. Some thing like the following should do it:[CODE]php_value display_errors 1
php_value error_reporting 2047
[/CODE]
Copy linkTweet thisAlerts:
@dirtauthorMar 16.2006 — purrrr.....THANKS ALOT GUYS.

the codings helped me....

and learned something for the past few days..

?
×

Success!

Help @dirt 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.17,
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,
)...