View Single Post
Old 05-14-2008, 03:01 AM   #2 (permalink)
sarmenhb
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

hi, you got a long way to go lol,
if your really interested in learning php first let me explain to you what it is.

you know how you make a simple .html file well, when you load the page you can go to view -> source code and view the source code of the page that was created etc..

what php does is when you put your php code into this page when you go and try to view the source code you wont see it , thats because php in reality are coded language rules that are executed by php's engine which is apache.

in general php is a dynamic language, if you notice when i enter this reply for you and i press submit, the data i type goes straight into a database and the page retreives the data back again to the page and displays what im typing to you.

if you want to run php locally on your pc and your using windows XP, i would suggest you try out wamp which can be found at wampserver.com/en

install the program then if you setup the default directorys when installing , all of your php files should be placed in c:\wamp\www

this is your root directory meaning this is where you should place your php files.

now to do a sample run of php type this into a textfile (notepad)

Code:
<?php

echo "this is php"; 
?>
then save the file as index.php (rewrite the existing file if it exists)

then go into your browser and type http://localhost

this is how you access the root directory from your browser.

http://localhost/

as for working with forms let me show you an example and will try my best to explain

Code:
<html>
<head>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
FName: <input type="text" name="fname"><br/>
LName: <input type="text" name="lname"><br/>
<input type="submit" name="submit" value="submit"><br/>
</form>
</body>
</html>
all this peice of code does is submit the page and nothing really happends because you havent told it to do anything. now let me show you what you can do

you can either
1) save the data entered into a database like mysql
2) email a user with the information opened
3) display what the user typed on a new page.


Code:
<?php 
//checks to see if the submit button is pressed, if so then it processes what are in the curly brackets

if(isset($_POST{'submit'])) {

//you can check to see if values were entered into the textboxes like this

if(!$_POST['fname'] || !$_POST['lname']) { die('empty fields found'); }

//btw, these slashes are for entering your comments into the code so you know what you are coding.

//lets put these values into a database

include("your connection string to the database.php");
$save = mysql_query("insert into yourtable values('{$_POST['fname']},{$_POST['lname']})");

if($save) { exit('your data was saved'); } 





hope this helps..




?>
<html>
<head>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
FName: <input type="text" name="fname"><br/>
LName: <input type="text" name="lname"><br/>
<input type="submit" name="submit" value="submit"><br/>
</form>
</body>
</html>
i didnt check to see what i typed but if you would like help i can be reached on aim: sarmenhb
__________________
no signature set
sarmenhb is offline  
Reply With Quote
The Following User Says Thank You to sarmenhb For This Useful Post:
kcnuk (05-21-2008)