PDA

View Full Version : Davids Login Tutorial


drakecai
04-23-2009, 07:01 AM
I followed all of David's steps and here is the code I ended with

<?php
require_once("Connections/connection.php");

// catch field data
$userid = $_POST['userid');
$password = $_POST['password');
$submitted = $_POST['submitted');

if ($userid && $password){
///////////////////////////////////////
$query = sprintf("SELECT * FROM users where user_name='$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
///////////////////////////////////////
}

if ($rowAccount){

echo "LegacyZ is currently in construction, please check back later.";

}elseif($submitted){

echo "Sorry, you have not signed in.";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="311" border="1" align="center">
<tr>
<th width="92" scope="col">Username:</th>
<th width="203" scope="col"><input type="text" name="userid" id="userid" /></th>
</tr>
<tr>
<th scope="col">Password:</th>
<th scope="col"><input type="text" name="password" id="password" /></th>
</tr>
<tr>
<th scope="col">&nbsp;</th>
<th scope="col"><p>&nbsp;
</p>
<p>
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="button" id="button" value="Submit" />
</p>
<p>&nbsp;</p></th>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>




I think its all right, I have this as my connection,php

<?php
///////////////////////////////////
@database = "localhost";
@username = "root";
@password = "";
//////////////////////////////////

@link = @mysql_connect('localhost', $username, $password);
@db = mysql_select_db($database, $link);

?>

With all that I got this error after typing in random information into the login and password box

File Not Found













Firefox can't find the file at /C:/Documents and Settings/Drake Cai/Desktop/LegacyZ/Website/<?php $_SERVER['PHP_SELF'];?>.







* Could the item have been renamed, removed, or relocated?
* Is there a spelling, capitalization, or other typographical error in the address?
* Do you have sufficient access permissions to the requested item?

davidj
04-23-2009, 08:07 AM
did you follow all tutorials from the begining?

have you tested your server?

have you ran a phpinfo file?

what happens when you key localhost into your browser address bar?

drakecai
04-24-2009, 04:41 AM
Tested my server through localhost

I got an error about my connection.php in line three

edbr
04-24-2009, 05:13 AM
@database = "localhost";
@username = "root";
@password = "";
is that
$database = "localhost";
$username = "root";
$password = "";

drakecai
04-24-2009, 06:12 AM
EDBR I don't get waht your saying... anyways I have changed my settings and I no longer am getting the error but now when I click the submitted button I do not get my two echos. I checked over them and i see no flaw in either one. Here is my updated code.

<?php
require_once["connections.php"];

////////////////////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];

if [$userid && $password]{
////////////////////
$query = sprintf["SELECT * FROM users where user_name = '$userid' and user_password = '$password'"];
$result = @mysql_query[$query];
$rowAccount = mysql_fetch_array[$result];
///////////////////
}

if [$rowAccount]{

echo "Admin you have logged in.";

}elseif[$submitted]{

echo "LegacyZ is currently under construction. Please check back later.";

}

?>

<title>LegacyZ Login</title>
<form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="200" border="1" align="center">
<tr>
<th scope="col">User ID:</th>
<th scope="col"><label>
<input type="text" name="userid" id="userid" />
</label></th>
</tr>
<tr>
<th scope="col">Password:</th>
<th scope="col"><label>
<input type="text" name="password" id="password" />
</label></th>
</tr>
<tr>
<th scope="col">&nbsp;</th>
<th scope="col"><label>
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="button" id="button" value="Submit" />
</label>
<label></label></th>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>

davidj
04-24-2009, 06:44 AM
conditional statements are invalid

your using [] but should be using ()

drakecai
04-24-2009, 10:45 PM
Alright so If I change all the brackets to () it should be fixed correct?

davidj
04-25-2009, 09:04 AM
its a start!

try it

drakecai
04-25-2009, 08:57 PM
Nope Doesn't work this is my updated code

<?php
require_once("connections.php");

////////////////////
$userid = $_POST('userid');
$password = $_POST('password');
$submitted = $_POST('submitted');

if ($userid && $password){
////////////////////
$query = sprintf("SELECT * FROM users where user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = mysql_fetch_array($result);
///////////////////
}

if ($rowAccount){

echo "Admin you have logged in.";

}elseif($submitted){

echo "LegacyZ is currently under construction. Please check back later.";

}

?>

<title>LegacyZ Login</title>
<form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="200" border="1" align="center">
<tr>
<th scope="col">User ID:</th>
<th scope="col"><label>
<input type="text" name="userid" id="userid" />
</label></th>
</tr>
<tr>
<th scope="col">Password:</th>
<th scope="col"><label>
<input type="text" name="password" id="password" />
</label></th>
</tr>
<tr>
<th scope="col">&nbsp;</th>
<th scope="col"><label>
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="button" id="button" value="Submit" />
</label>
<label></label></th>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>


Well same problem still, when I press the submit button the screen flashes once and none of the echos show up.

davidj
04-26-2009, 11:03 AM
if you have lifted that from the same page then you need <html <head and <body tags

drakecai
04-26-2009, 08:34 PM
Still Doesn't work, this is what I put

<?php
require_once("connections.php");

////////////////////
$userid = $_POST('userid');
$password = $_POST('password');
$submitted = $_POST('submitted');

if ($userid && $password){
////////////////////
$query = sprintf("SELECT * FROM users where user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = mysql_fetch_array($result);
///////////////////
}

if ($rowAccount){

echo "Admin you have logged in.";

}elseif($submitted){

echo "LegacyZ is currently under construction. Please check back later.";

}

?>
<html>
<head><title>LegacyZ Login</title>
</head>
<body><form id="form1" name="form1" method="post" action="">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="200" border="1" align="center">
<tr>
<th scope="col">User ID:</th>
<th scope="col"><label>
<input type="text" name="userid" id="userid" />
</label></th>
</tr>
<tr>
<th scope="col">Password:</th>
<th scope="col"><label>
<input type="text" name="password" id="password" />
</label></th>
</tr>
<tr>
<th scope="col">&nbsp;</th>
<th scope="col"><label>
<input name="submitted" type="hidden" id="submitted" value="1" />
<input type="submit" name="button" id="button" value="Submit" />
</label>
<label></label></th>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>

davidj
04-26-2009, 08:45 PM
have you setup your database?

drakecai
04-27-2009, 12:46 AM
Yes I have setup my database. I don't think that is the problem because if the database was offline then it would echo the elseif code.

davidj
04-27-2009, 12:47 AM
does the account your checking for exist in the database

drakecai
04-27-2009, 02:06 AM
yea it does exist in the database

drakecai
04-27-2009, 02:09 AM
Perhaps my folder that i stored everything will help you.

http://www.mediafire.com/file/ryzmzhymwya/Website.rar

drakecai
04-30-2009, 07:02 AM
No help? Anyone help?

davidj
04-30-2009, 07:08 AM
contact me on messenger