Page 1 of 1

Few Questions.... PHP Newbie ( but getting better! =)

Posted: Thu Oct 03, 2002 3:55 pm
by infolock
Ok, first of all, thanks to everyone that has been helping me out as I go along the dark and dreaded hallways of learning a totally different language from scratch ;) Lots gave me a load of information on setting up php on my servers, and now it's working like it should!

However, I DO still have some problems/issues that I would love to see if people could answer for me....

It's basically dealing with php in itself. I have found in my expierience as a programmer, the better way ( not always the best ) to understand new code is to look at how other's use the syntax's involved, and ways they are setting up the code to work as it progresses...

However, heh, php is a little bit different from the rest ;) Instead of it being the master, it's basically instead a slave. In other words, you have to have one application setup the things you want to do, and then call it for actions..

For example, a login script. You build a script that is going to make calls to a MySQL database to lookup validations on a Username/Password, and if it's there, you redirect them to another page, or yadda yadda yadda...

My problem lies here... I do not understand how to make php do these things.

Here is a better eplanation. I am using the following script :

Code: Select all

<? 
# Login Code Written by Matt Slavin
# Email Me At neophite17@hotmail.com for questions or comments.

if((!$Username) | (!$Password)) &#123;
print ("Please Enter In THe Correct Name");
&#125; 

mysql_connect("localhost","User_Name_here","Password_Here");
mysql_select_db("My_Database_Here");

# This part is sort if ya want to. I would suggest it.
# Make your login page have the main value of Password
#Comment Out if you Want too
$Password = md5($Password);

$sql = "select * from My_Table where Password=$Password and Username=$Username";
$result = mysql_query($sql);
$num = mysql_numrows($result);

# If Login Is Okay Do What You Want TO DO to Them
if ($num == "1") &#123;
print ("Logged in okay");
#Or you can send them somwhere nice like hawaii
header("Location: http://localhost/bob/success.htm");
exit;
# or even fetch feild about them or save sessions
session_start();
session_register(Username);
&#125;

# And we must a have a default error message if login fails
if ($num == "0")&#123;
print ("Sorry Bub You Need Some Manners In Password");
&#125;


?>
I set this into a login.php file, create the db's as required above, and run the script by typing http://localhost/bob/login.php...

When I load this script, all it does is give me a blank page with NO OUTPUT, and with NO INPUT possibilities ( ie, no boxes asking for a username/password, etc. etc ... )


My question is, do I have to create an HTML/PHP file that asks for the login/password, and then in the ON-SUBMIT clause through them over to the login.php script, or am I just missing something here? And, if I am suposed to do it like I think I am, could someone give me a small example of how this works?

Sorry for being a pain, but as I said, I'm still in the learning process... Again, I have already read the manual ( which does not help. Basically just gives you the syntaxes that are supported in php, but no basic idea of how to handle such script applications .... )

Thanks in advance!

Posted: Thu Oct 03, 2002 4:26 pm
by mr_griff
You are correct in thinking that you need to first have a page that sends the username and password to your login.php script.

The easiest way when starting out is to make two pages. One with the login form and one that processes the login.

Make a page like this that submits the username and password to the login.php page for processing the login.

Code: Select all

<html>
<head>
  <title>Please Login</title>
</head>
<body>

<form action="login.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="buttonSelection" value="Login">
</form>

</body>
</html>
It it possible to do this with one script, by checking to see of someone submitted a username and password, if not display a form that submits username and password to itself.

Posted: Thu Oct 03, 2002 4:33 pm
by infolock
thanks for in the input, it is greatly appreciated :D

php to me is one of the most powerful languages on the web. Thankfully, it's also one of the hardest to get use to ;) which makes programmers lives a hell of a lot more secure hehe. But, also, thankfully, there are people to help us newbies out as we master our ninja skills. Thanks again!