Hi guys, i want to create a registration page which has the fields like name,username,gender,dateofbirth,maritalstatus,etc...

i have already created the form using html. now i need to encrypt the php code to insert these datas into the database which i have already created.
Additionly i need to validate these fields using javascript

Please explain me from scratch with a simple code don't use complicated codes as a novice its difficult for to understand

Thanks

Thank you cheelee

please explain me with the code

hi kali

please examine the code below:


<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

the main key here is the code
action="welcome.php" method="post"


this means you need to create a .php file, for example above it is "welcome.php"
the form entries by the user will be sent to the php

in the php file put following code:
<html>
<body>

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.

</body>
</html>

after the form is submitted you will see the output shown on screen.
hope this helps!

Member Avatar for diafol

> please explain me with the code

How about you show us your code and we'll tell you how to improve it. This isn't a 'give me some code' forum. You can use Google to get a script. Buy a book on html/php. Where have you gotten so far?

<?php
require_once('conn.php');



if(isset($_POST['submit']))
{
 if($_POST['name']=="" ||$_POST['username']=="" || $_POST['password']=="" || $_POST['gender']=="" || $_POST['dob']=="" || $_POST['resitown']=="" || $_POST['nativetown']=="" || $_POST['qualify']=="" || $_POST['jobdetail']=="" || $_POST['income']==""|| $_POST['disability']==""|| $_POST['maritalstatus']==""|| $_POST['emailid']==""|| $_POST['phoneno']==""|| $_POST['mobile']==""|| $_POST['address']=="")
 {
 $err="All Fields are required";
 }
$namecheck = mysql_query("SELECT username FROM personal WHERE username ='$username'");

$count = mysql_num_rows($namecheck);


    if($count!=0)//Record is present!

    {

        die("<h2>ERROR: The Username is already taken!</h2>");
    }


 $_POST["dob"]= $_POST["Year"]."-". $_POST["Month"]."-". $_POST["Date"];

  mysql_query("insert into personal(name,username,password,gender,dob,resitown,nativetown,qualify,jobdetail,income,disability,maritalstatus,emailid,phoneno,mobile,address) values('$_POST[name]','$_POST[username]','$_POST[password]','$_POST[gender]','$_POST[dob]','$_POST[resitown]','$_POST[nativetown]','$_POST[qualify]','$_POST[jobdetail]','$_POST[income]','$_POST[disability]','$_POST[maritalstatus]','$_POST[emailid]','$_POST[phoneno]','$_POST[mobile]','$_POST[address]')") or die(mysql_error());
  $err="User Added Successfully.<a href='index.php'>Click here to Login.</a>";

}
?>

<!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=utf-8" />
<title>Untitled Document</title>
<link href="layout.css" rel="stylesheet" style type="text/css"/>
</head>

<body>

<div id="header">

</div>
<div id="nav">
<ul>

<li><a href="home.php" id="n1" target="_self">Home</a></li>
<li><a href="Register.php" id="n2" target="_self">Register</a></li>
<li><a href="wedding.php" id="n3" target="_self">Wedding</a></li>
<li><a href="contact.php" id="n4" target="_self">Contact</a></li>
</ul>
</div>

<div id="main">
  <div id="left">
  
<?php if(isset($_POST['submit']))
{echo $err;}

?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" name="submit">
<table>
<tr>

<td>Name</td>
<td><input type="text" name="name" value="" size="30" maxlength="30"/></td>
</tr>

<tr>
          <td>Username</td>
          <td><input name="username" type="text" size="30" maxlength="30" /></td>
        </tr>
        <tr>
        
<tr>
<td>Password</td>
<td><input name="password" type="password" value="" size="30" id="password" />
</td>
</tr>
<tr>
          <td>Gender:</td>
          <td>
      
          <input type="radio" name="gender" value="Male" id="Gender_0" />
          Male
        
          <input type="radio" name="gender" value="Female" id="Gender_1" />
          Female
      </td>
        </tr>
         
      <tr>
        <td>Date of birth</td>
        <td><select name="Date">  <option>Date</option>
        
		  <?php for ($i=1;$i<=31;$i++){ ?>
          
          <option><?php echo $i?></option>
          <?php }?>
        </select>
          <select name="Month"/>    <option>Month</option>
          
		   <?php for ($i=01;$i<=12;$i++){ ?>
           
          <option><?php echo $i?></option>
          <?php }?>
          
          </select>
          
          <select name="Year">   <option>Year</option>
           
            <?php for ($i=2011;$i>=1950;$i--){ ?>
           
            <option><?php echo $i?></option>
            <?php }?>
      </select> </td>
      </tr>
      <tr>
      <?php

  //calculate years of age (input string: YYYY-MM-DD)
  function dob ($dob){
    list($year,$month,$day) = explode("-",$dob);
    $year_diff  = date("Year") - $year;
    $month_diff = date("Month") - $Month;
    $day_diff   = date("Date") - $Date;
    if ($day_diff < 0 || $month_diff < 0)
      $year_diff--;
    return $year_diff;
  }
  ?>
<td>Age</td>
<td><input name="age" type="text" value="<?php print $year_diff; ?>" size="10" id="age" /></td></tr>

     
       <tr>
        <td>Residing Town/City:</td>
        <td><input name="resitown" type="text" size="30" maxlength="30" /></td>
      </tr>
     
      <tr>
        <td>Native Town/City :</td>
        <td><input name="nativetown" type="text" size="30" maxlength="30" /></td>
      </tr>
      <tr>
<tr>
 <tr>
        <td>Qualification</td>
        <td><select name="qualify">
          <option>Phd</option>
          <option>M.B.B.S</option>
          <option>B.E/B.tech</option>
          <option>Bsc</option>
          <option>Bcom</option>
          <option>Diploma</option>
          <option>Other</option>
        </select></td>
      </tr>
<tr>

 <tr>
        <td>Job Details :</td>
        <td><input name="jobdetail" type="text" size="30" maxlength="20" /></td>
      </tr>
       <tr>
      <td>Income</td>
            <td><input name="income" type="text" size="30" maxlength="30" /></td>
      </tr>
      <tr>
        <td>Disability(if any) :</td>
        <td>
          <label>
            <input type="radio" name="disability" value="yes" id="Disability_0" />
            Yes</label>
          <label>
            <input type="radio" name="disability" value="no" id="Disability_1" />
            No</label>
        </td>
      </tr>
      
      <tr>
        <td>Marital Status :</td>
        <td>
          <label>
            <input type="radio" name="maritalstatus" value="un married" id="Maritalstatus_0" />
            un married</label>
          <label>
            <input type="radio" name="maritalstatus" value="Divorced" id="Maritalstatus_1" />
            Divorced</label>
          <label>
            <input type="radio" name="maritalstatus" value="Widow/widower" id="Maritalstatus_2" />
            Widow/widower</label>
        </td>
      </tr>
       <tr>
        <td>Email ID :</td>
        <td><input name="emailid" type="text" size="30" maxlength="30" /></td>
      </tr>
      <tr>
        <td>Phone no:</td>
        <td><input name="phoneno" type="text" size="30" maxlength="30" /></td>
      </tr> <tr>
        <td>Mobile no :</td>
        <td><input name="mobile" type="text" size="30" maxlength="30" /></td>
      </tr>
       <tr>
        <td>Address</td>
        <td><input name="address" type="text" size="30" maxlength="90" /></td>
      </tr>
<td><input type="submit" name="submit" value="Sumbit" id="submit"/></td>
</tr>
</table>   

</form>
    </table>
    
    
  </div>
</div>
<div id="footer">
</div>
</body>
</html>

Thank you cheelee and ardav this is de code. i want to validate this page using javascript. please use simple code

Member Avatar for diafol

OK nice one. For javascript validation, have a look at jValidate for jQuery, or even YAV if you don't want to use jQuery. However, js validation can be circumvented, so you'll still need to use server-side (php-based) validation.

An example of validation filters can be found here:

http://php.net/manual/en/filter.filters.validate.php

You also need to sanitize your input with mysql_real_escape_string().

You seem to be sending the form to itself (same page). This can cause problems with a reload/refresh action - you can end up sending the form twice. So, send the form to a different file (a form handler).

Thank you for your help and i will do the same

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.