Saturday, 13 July 2019

Project-2


<html>
<body bgcolor="pink">
<form  action="inserttable.php" method="post">
<fieldset>
<legend>Student Registration Form</legend>
Name<input type="textbox"  name ="s_name" placeholder="ex. rajesh"><br><br><br>
F_name<input type="textbox"  name ="f_name" placeholder="ex. Mr. Abhinash"><br><br><br>
Email<input type="textbox" name="email" placeholder="abc1234@gmail.com"><br><br><br>
Phone<input type="textbox"  name ="phone" placeholder="6789452390"><br><br><br>

Address<br><textarea name= "address"  rows="4" cols="50"name ="email"  placeholder="ex. abc@gmail.com"></textarea><br>
<br><br><br>
Gender:<br>
<input type="radio" name ="r1" value="Male">Male<br>
<input type="radio" name ="r1" value="female">Female<br>
<br><br><br>
Hobby:<br>
<input type="checkbox" name ="checklist[]">Spots<br>
<input type="checkbox" name ="checklist[]">Reading<br>
<input type="checkbox" name ="checklist[]">Dance<br>
<input type="checkbox" name ="checklist[]">Sing<br>
<br><br><br>
<input type="submit" value="register" name="submit">
</fieldset>
</form>
</body>
</html>
Program name : inserttable.php
<?php
if(isset($_POST['submit']))
{
$n=$_POST['s_name'];
$f=$_POST['f_name'];
$p=$_POST['phone'];
$a=$_POST['address'];
$s=$_POST['r1'];
$e=$_POST['email'];
}
$con= new mysqli("localhost","root","","student2");

$sql="INSERT INTO admission(S_name,phone,Email,Sex,Address)VALUES('$n','$p','$e','$s','$a')";
if(mysqli_query($con,$sql))
{
          echo "Your Record Successfully Inserted";    
 }
 else
 {
           echo mysqli_error($con);
 }
?>

Again see that we forgot to make column of f_name,  So again we can alter table for f_name
<?php
$con=new mysqli("localhost","root","","student2");

$sql="ALTER TABLE admission ADD F_name VARCHAR(40) NOT NULL AFTER S_name";
if(mysqli_query($con,$sql))
{
          echo "successfully table alter";
}
?>

See , Father name is not shown in database table, for that you have edit inserttable.php  command
You have to edit red highlighted line.
<?php

if(isset($_POST['submit']))
{
$n=$_POST['s_name'];
$f=$_POST['f_name'];
$p=$_POST['phone'];
$a=$_POST['address'];
$s=$_POST['r1'];
$e=$_POST['email'];
}
$con= new mysqli("localhost","root","","student2");

$sql="INSERT INTO admission(S_name,phone,Email,Sex,Address,F_name)VALUES('$n','$p','$e','$s','$a','$f')";
if(mysqli_query($con,$sql))
{
          echo "Your Record Successfully Inserted";    
 }
 else
 {
           echo mysqli_error($con);
 }
?>

Now pay attention your  F_name of first row still blank. So you need to update that table.
<?php
$conn=new mysqli("localhost","root","","student2");
$sql="UPDATE admission SET F_name = 'Sukh' WHERE id='6'";
if(mysqli_query($conn,$sql))
{
          echo "Record updated successfully";
}
else
{
          echo mysqli_error($conn);
}
?>

Fetch data from table
<html>
<head>
<style>
table,th,td
{
          border:1px solid black;
}
th,td{
          height:50px;
          width:90px;
}
</style>
<body>
<?php
$conn= new mysqli("localhost","root","","student2");
$sql="SELECT * FROM admission";
$result=$conn->query($sql);
if($result->num_rows>0){
          echo "<table border='1'>";
 echo "<tr><th>ID</th><th>S_name</th><th>F_name</th><th>phone</th>";
 echo "<th>address</th></tr>";
while($row=$result->fetch_assoc()){
          echo "<table border='1'>";
          echo "<tr><td>".$row['id']."</td><td>".$row['S_name']."</td>";
          echo "<td>".$row['F_name']."</td>";
          echo "<td>".$row['phone']."</td>";
echo "<td>".$row['Address']."</td></tr>";}}
echo "</table>";
?>

No comments:

Post a Comment