Page 1 of 1

Any suggestions on what I should start with? :)

Posted: Thu Oct 03, 2002 7:57 pm
by infolock
Anyone have some suggestions on what I should try and learn to do first with PHP? I am starting out learning the basics of user authroization and sending/retrieving info with mysql, but I feel like I'm not starting where I should. Anyone have some pointers? Thanks! 8O

Posted: Thu Oct 03, 2002 9:05 pm
by hob_goblin

Posted: Thu Oct 03, 2002 11:58 pm
by rev
I know some may disagree, but regardless, my suggestion is after you get a comfortable handle on the syntax of PHP (very similar to C), I suggest going OOP (Object Oriented Programming) immediately. Once you go OOP, there is no going back - and you won't want to go back. ;)

Check out classes, methods, functions, lions, tigers, bears, (oh my!) and learning to use objects to limit randomness in your code. If there are two instances in your script where the same code sniplet is used, it should be an object. :)

I know this may seem a bit daunting and confusing at first, but if you go through the growing pains and stick with it you will find your PHP (and any other language) scripts to do what scripting/programming was meant to do - make your life easier. On the contrary, bad scripting/programming can make your life hell. :)

Code: Select all

<?php
class theBasics {
	var $not_so_sure;
	
	function theBasics() {
		echo "U'can dew eht!<br>\n";
		$this->not_so_sure = 1;
	}
	
	function verySimple() {
		if(is_numeric($this->not_so_sure)) echo "It's actually quite simple!<br>\n";
	}
}

$theBasics = new theBasics;
$theBasics->verySimple();
?>
Output:
U'can dew eht!
It's actually quite simple!

Good luck! If you run across stumbling blocks, just post a question or get your keyboard dirty poking around on http://www.php.net ;)

http://www.php.net/manual/en/language.oop.php

Posted: Fri Oct 04, 2002 12:30 pm
by infolock
Hey, thanks for the info! Yeah, PHP is a mind in it's own, and I'm loving it. Never had so much fun getting lost and then finding myself again hehe :D

However, I do seem to have a problem. Will probably seem kinda simple to the rest of ya, but to me, it's mind boggoling...

As I stated, I am using a script with the following code :

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 have indeed created the databases needed ( in my case, my db is called auth, and table called userinfo, with the field names of username and password ).

Now, I can connect fine with NO PROBLEMS to the databse...

However, it's not pulling the data, comparing, or handling like it should.

In other words, I did a basic Insert INTO table userinfo values ('bob','bob');

it saves the info, and places a line in the table with bob under the username, and bob under the password.

i do a select * from userinfo and it dispays that I have bob and bob under the correct fields. However, when I try and log in with bob and bob with the login, i only get the message Please Enter In THe Correct Name.

which is what happens if one uses the incorrect username/password.

Now, I found out whilie reading my manual that in order to use $num = mysql_numrows($result) successfully, I have to run a php command in order to do this?? I dunno, I'm confused.

I have done NOTHING except install apache, edit the http.conf file, and install mysql. Is there something special I need to do with mysql or php in order to have it correclty read/display database information?


for those of you wondering, i did log in with a mysql username, and changed the password, and then edited that in the above script. thanks for any information you can provide me with! 8O

Posted: Fri Oct 04, 2002 2:05 pm
by rev
When you created the user/pass record in your DB, did you MD5 the password?

If you look in the script you are using, it takes the password typed by the web user and MD5s it before submitting a request for validity to the DB.

Posted: Fri Oct 04, 2002 4:09 pm
by infolock
pardon my stupidity, but what the hell is md5?? lol..

Posted: Fri Oct 04, 2002 5:53 pm
by infolock
ok, n/m, i found out what you are talking about. MD5 is just an encryption method used in php... doesn't really effect the password at all, just a way to use it, so wouldn't matter if i used it or not. but, for the sake of argument, yes i took that line out as I did not know what it was before ( and since the comments say I can comment it out, didn't think it would hurt ).

I think there is a module I have to load, or some type of command I have to use when installing php, in order to get this to work ( ie php --mysql_somethingoranother ) or something to this effect... Dunno, just know I'm clueless and loving is :D

any info though would be appreciated 8O

Posted: Fri Oct 04, 2002 9:25 pm
by mazzi
can you copy give us a link to a page with phpinfo();