Sending a Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mhs131
Forum Newbie
Posts: 1
Joined: Sun Apr 01, 2007 6:33 pm

Sending a Form

Post by Mhs131 »

Burrito | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Ok, I'm very much a newby at php, but I have a code here that when the correct username and password is created it points to a url.

Code: Select all

<?
/*The below Var ($) is your error page,
feel free to replace it with your own page.*/
$error_page = "http://www.test.com/failedlogin.html";

$user = Array();
$links = Array();

#---Here is where you edit your list of usernames----#

/*account 1*/
$user['Jason'] = 'Photolocker';
$links['Jason'] = 'http://www.test.com/test.html;

/*account 2*/
$user['Gary'] = 'Claire';
$links['Gary'] = 'http://www.test.com';

#---------------End user names list------------------#

$xuser = $_POST[user];
$xpass = $_POST[pass];

if (array_key_exists($xuser, $user)) {
   if ($xpass == $user[$xuser]){
		echo ('Logging in...<br><br><br>');
		echo ('<script language="javascript">location.href=\''.$links[$xuser].'\';</script>');
   }else{
		echo ('<script language="javascript">location.href=\''.$error_page.'\';</script>');
   }
}else{
		echo ('<script language="javascript">location.href=\''.$error_page.'\';</script>');
}
?>
My question is how I would create the form to read this the ones I have when submitted go right to the failedlogin.html

Any help would be appreciated.

Thanks


Burrito | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

There's nothing wrong with being a newbie--we all were, when we started. But it takes more than finding a script that someone else wrote for some purpose and thinking that you can simply ask somebody else to tell you how to make it work.

I sincerely recommend that you do some reading on the principles of programming, particularly web programming. You have to understand how the web server and the browser exchange information, especially for something like validating a login. Your sample script seems about the worst way to go about it that I can think of, using arrays that would have to be maintained in your script.

There are numerous tutorials online and just hundreds of books available. Start at the beginning. If you think you can jump into the middle of it, you're only fooling yourself.
Post Reply