Before running this you have to install "PhpMyAdmin"or "wamp"or "xampp" in your pc. then open any browser and write in Url bar "Localhost/phpmyadmin" and here we make our Database,
Now open one more tab in browser and open "localhost/Filename". we all know the ip address of localhost is 127.0.0.1
In Php for printing anything we use echo"statement". in thiscode i also perform the validation.
Code
- <?php
- mysql_connect("localhost","root","");
- mysql_select_db("DATABASE NAME");
- ?>
- <html>
- <head>
- <title>insert</title>
- </head>
- <body>
- <form name="frm" method="post">
- <table border="1" bgcolor="#9999CC" cellpadding="5" cellspacing="5" align="center" bordercolor="#9966FF";>
- <caption style="font-size:50px">SIGN UP</caption>
- <b>
- <tr>
- <td style="color:#FFF">Name</td>
- < td><input type="text" name="name" value="<?php echo $_POST['name']?>"></td>
- </tr>
- <tr>
- <td style="color:#FFF">Father's name</td>
- <td><input type="text" name="fname" value="<?php echo $_POST['fname']?>"></td>
- </tr>
- <tr>
- <td colspan="2" align="center"><input type="submit" name="submit"></td>
- </tr>
- </b>
- </table>
- <?php
- if(isset($_POST['submit']))
- {
- if($_POST['name']=="")
- {
- echo "please enter your name";
- }
- elseif($_POST['fname']=="")
- {
- echo "please enter father name";
- }
- else
- {
- $strQuery ="insert into TABLE NAME(name,father_name) values('".$_POST['name']."','".$_POST['fname']."')";
- $strResult=mysql_query($strQuery) or die("here some error".mysql_error());
- }
- }
- if($strResult)
- {
- echo "thanks for register";
- }
- ?>
- </form>
- </body>
- </html>