Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
problem creating a login site
Old 08-11-2004, 03:10 PM problem creating a login site
Junior Talker

Posts: 1
Trades: 0
OK, I have been trying for a few days now to get this working and I am still unable to. I can get the login form to submit to the processing program written in php but then the web browser just sits there not doing a thing. Here's the processing code see if you can help:

<?php

session_start();
session_register('auth');
session_register('tries');
include ('include/1040.inc');

$auth = 'no'; //automatically assumes user is not allowed in the site

if ($tries >= 3)
{
header ("Location: fail.php");
die();
}

$connection = mysql_connect($host,$user,$ps) //connects to the MySQL server
or die ("Could not connect to the server.");

$db = mysql_select_db($dbname,$connection) //connects to the MySQL database
or die ("Could not connect to database.");


$sql = "SELECT use_username FROM userinfo WHERE use_username='$user'";
$result = mysql_query($sql)
or die("Couldn't execute query 1");
$num = mysql_num_rows($result);
if ($num == 1)//login name was found
{
$sql = "SELECT use_username FROM userinfo WHERE use_username='$user' AND use_password='$password'";
$result2 = mysql_query($sql)
or die("Couldn't execute query 2");
$num2 = mysql_num_rows($result2);
if ($num2 > 0)
{
$auth = "yes";
$tries = $tries + 1;
if ($page != '')
{
mysql_close($connection);
header ("Location: index.php");//change after login works
die();
} //loads the users requested page
else
{
mysql_close($connection);
header ("Location: index.php");
echo "$tries";
die();
}//if no page is requested index is loaded
}
else //username or password is not correct
{
mysql_close($connection);
$tries = $tries + 1;
header ("Location: form.php");//sends user to the login form
die("Your username or password is wrong, please try again.");
//lets the user try again
}
}
kb3hkg is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-11-2004, 04:26 PM
Skilled Talker

Posts: 63
Trades: 0
i'm sorry, but your code is quite complex for this task, i'm just too busy to read & understand the whole thing

here's some general pointers:

1) make sure u r actually connecting to the DB. if u'r not connected, but trying to run queries - that can result in blank page on some PHP setups.

2) try to do it without an "include". includes sometimes produce blank pages.

3) use $_SESSION global var instead of session_register's. it works better.
antoshka is offline
Reply With Quote
View Public Profile Visit antoshka's homepage!
 
Old 08-11-2004, 04:57 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
as well, instead of calling form variables like $user. Call them like this $_POST['user'].
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 08-11-2004, 06:49 PM
Unknown.

Posts: 1,693
Trades: 0
Or you could always just define the $user variable at the begining...

$user = $_POST['user'];

-James
Dark-Skys99 is offline
Reply With Quote
View Public Profile
 
Old 08-11-2004, 06:59 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Generally, if your only going to use a variable once then it's best to keep them in the superglobal array (IMO). That way you don't have useless variables hanging around and you will always know where $_POST['user'] came from (a form, obviously).
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 08-11-2004, 07:01 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
That and it will use less memory. No need to waste system resources.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to problem creating a login site
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.15115 seconds with 12 queries