Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

1.Write PHP code to accept and insert customer details from customer table. After successful insertion, display customer details in proper format.

1.> Write PHP code to accept and insert customer details from customer table. After successful insertion, display customer details in proper format.


Customer details.html

<html>
<body>
<center>
<h1> <u> Registration Form</u></h1>
<form action="customer.php">
<table border="0" width="30%" height="20%">
<tr>
<td>Name:</td>
<td><input type="text" name="cname"></td>
</tr>
<tr>
<td>Gender:</td>
<td><input type="radio" name="cgen" value="M">Male</td>
<td><input type="radio" name="cgen" value="F">Female</td>

</tr>
<tr>
<td>Date of Birth(YYYY-MM-DD):</td>
<td><input type="text" name="cdob"></td>
</tr>
<tr>
<td>Contact_No:</td>
<td><input type="text" name="cno"></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="ccity"></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="cstate"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Save"></td>
</tr>
</form>
</center>
</body>
</html>


customer.php

     <?php
      $con=mysql_connect("localhost","root","mysql") or die(mysql_error());
      mysql_select_db("Cust_Deatails",$con) or die(mysql_error());
     
     $cname=$_REQUEST["cname"];
     $cgen=$_REQUEST["cgen"];
     $cdob=$_REQUEST["cdob"];
     $cno=$_REQUEST["cno"];
     $ccity=$_REQUEST["ccity"];
     $cstate=$_REQUEST["cstate"];

     $insert_query="INSERT INTO customer(cname,cgen,cdob,cno,ccity,cstate) 
                  VALUES(' ".$cname." ' , ' ".$cgen." ', ' ".$cdob." ' , '".$cno."' , ' ".$ccity." ' , ' ".$cstate." ')";

            //Execute the query on the database

            mysql_query($insert_query,$con) or die(mysql_error());
            echo "<center><h3>Customer  details have been saved successfully !!</h3><center>";
           
            // Displaying details
            $select_qry="SELECT * FROM  Customer";
            echo "<center><table border=1> <tr><th>Customer_ID</th> <th>Name</th><th>Gender</th><th>Birthdate</th><th>ContactNo</th><th>City</th><th>State</th></tr></center>";

    $result=mysql_query($select_qry,$con) or die(mysql_error());
     
      while($row=mysql_fetch_array($result))
      {
     echo "<center><tr><td>".$row['cid']."</td><td>".$row['cname']."</td><td>".$row['cgen']."</td><td>".$row['cdob']."</td><td>".$row['cno']."</td><td>".$row['vcity']."</td><td>".$row['vstate']."</td></tr></center>";
      }
     
            //close the database connection

    mysql_close($con);
     

  ?>

No comments:

Post a Comment