Hi!
This will be helpful if you're a newbie or desperately finding some code to copy paste during your very first site project experience with PHP.
Anyway, try to learn something out of this as it's easy to understand as well as simple to follow. As usual the guide is given in steps so that you don't need to bother reading long sentences to keep going with the guide.
Let's go.
1. First, you need to create a Directory(Windows/Linux) to save your work & you've to keep this in your server. (if you're using localhost, keep it inside htdocs directory).
2. Then, run the following MYSQL code & create table to enter data.
3. Then, Create a index.php file & put the following code in it.
4. Then, create redirect.php & put the following code there.
5. Then,create signup.php file & put the follwing code.
Now, File Seems like follows inside the directory.
6. Now, run Web Browser & type http://localhost/folder in the address bar.
7. There's Few notes to make. In signup.php line 3 can be replaced with your site url, username & password. Naming text boxes in index.php like :
<input type="text" name="txt_email" .. is important in order to get their values in signup.php.
Enjoy the Code !
This will be helpful if you're a newbie or desperately finding some code to copy paste during your very first site project experience with PHP.
Anyway, try to learn something out of this as it's easy to understand as well as simple to follow. As usual the guide is given in steps so that you don't need to bother reading long sentences to keep going with the guide.
Let's go.
1. First, you need to create a Directory(Windows/Linux) to save your work & you've to keep this in your server. (if you're using localhost, keep it inside htdocs directory).
2. Then, run the following MYSQL code & create table to enter data.
create database phpdb; use phpdb; create table test( email varchar(100) not null, password varchar(20) not null );
3. Then, Create a index.php file & put the following code in it.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>This is PHP Example</title> </head> <body> <form action="signup.php" method="post"> <table width="629" height="191" border="1"> <tr> <td width="241">Enter Email Address </td> <td width="372"><input type="text" name="txt_email" /></td> </tr> <tr> <td>Enter Password </td> <td><input type="password" name="txt_password" /></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit" name="btn_submit" /></td> </tr> </table> </form> </body> </html>
4. Then, create redirect.php & put the following code there.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>This is PHP File</title> </head> <body> <?php $red = $_REQUEST["msg"]; echo $red."<br/>"; ?> <br/> <a href="index.php" target="_parent">GO HOME</a> </body> </html>
5. Then,create signup.php file & put the follwing code.
<?php $con = mysql_connect("localhost","root",""); if(!$con) { $msg="Can't Connect to the Database ".mysql_error(); } else { $dbCon = mysql_select_db("phpDB"); if(!$dbCon) { $msg = "Can't Connect to the Table ".mysql_error(); } else { $email = $_POST["txt_email"]; $pword = $_POST["txt_password"]; $query = mysql_query("INSERT INTO test VALUES('$email','$pword')"); if(!$query) { $msg= "Can't Insert Values to the Table".mysql_error(); } else { $msg = "Successfully Added to the Table !"; } } } header("Location: redirect.php?msg=".$msg); ?>
Now, File Seems like follows inside the directory.
6. Now, run Web Browser & type http://localhost/folder in the address bar.
7. There's Few notes to make. In signup.php line 3 can be replaced with your site url, username & password. Naming text boxes in index.php like :
<input type="text" name="txt_email" .. is important in order to get their values in signup.php.
Enjoy the Code !
No comments:
Post a Comment