Tuesday, 23 July 2019

student-5 search


</form>

 <form action = "viewrecord.php" method = "GET">
Search a Record: <input type = "text" name = "search">
<input type = "submit" name = "submit" value = "Find Now">
</form>

       <?php
if(isset($_GET['search'])){
       $search_record = $_GET['search'];
      
       $query2 = "SELECT * FROM  details where Name = '$search_record' OR roll = '$search_record' ";
       $run2 = mysqli_query($conn,$query2);
      
       while($row2 = $run2->fetch_assoc())
       {
              $email=$row2['Email'];
              $name123= $row2['Name'];
      
       ?>
       <table width = '800' bgcolor = 'yellow' align = 'center' border = '1'>
       <tr align = 'center'>
      
<td><?php echo $name123; ?></td>
<td><?php echo $email; ?></td>

</tr>
</table>
<?php }} ?>




Friday, 19 July 2019

student project-4


First we are try for delete
<html>
<head>
<style>
table,th,td
{
        border:1px solid blue;
}
th{
        background-color:red;
}
th,td{
        height:50px;
        width:90px;
}
</style>
</head>
<body>
<table border="1">
<tr><th colspan="8">view all records</th></tr>
<tr><td>Roll No.</td><td>Name</td>
<td>email</td><td>website</td>
<td>gender</td>
<td>edit</td>
<td>delete</td>
<td>details</td></tr>


<?php
$conn= new mysqli("localhost","root","","student3");
$sql="SELECT * FROM details";

$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
        $id=$row['roll'];
        echo "<table border='1'>";
        echo "<tr><td>".$row['roll']."</td><td>".$row['Name']."</td>";
        echo "<td>".$row['Email']."</td>";
        echo "<td>".$row['Website']."</td>";
echo "<td>".$row['Gender']."</td>";
echo "<td><a href = 'edi.php?edit=<?php echo $id; ?>'>Edit</a></td>
  <td><a href='del.php?id=".$row['roll']."'>del</a></td>
<td>details</td></tr>";
}
echo "</table>";

?>

Del.php
<?php
$id = $_GET['id'];

$conn= new mysqli("localhost","root","","student3");

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "DELETE FROM details WHERE roll = $id";

if (mysqli_query($conn, $sql)) {
    mysqli_close($conn);
    header('Location: viewrecord.php'); //If book.php is your main page where you list your all records
    exit;
} else {
    echo "Error deleting record";
}

?>

student project-3


<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";

if (isset($_POST['submit'])) {
  if (empty($_POST["name"])) {
    $nameErr = "Name is required";
  }
 

  if (empty($_POST["email"])) {
    $emailErr = "Email is required";
  }
 

  if (empty($_POST["website"])) {
    $website = "";
  }
 

  if (empty($_POST["comment"])) {
    $comment = "";
  }
 

  if (empty($_POST["gender"])) {
    $genderErr = "Gender is required";
  }
$n=$_POST['name'];
$e=$_POST['email'];
$w=$_POST['website'];
$c=$_POST['comment'];
$g=$_POST['gender'];

}
?>

<form method="post" action="w3.php">

Name: <input type="text" name="name">
* <?php echo $nameErr;?>
<br><br>
E-mail:
<input type="text" name="email">
* <?php echo $emailErr;?>
<br><br>
Website:
<input type="text" name="website">
<?php echo $websiteErr;?>
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="other">Other
* <?php echo $genderErr;?>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>

For connection.php
<?php
$con=mysqli_connect("localhost","root","");

$sql="CREATE DATABASE student3";

if(mysqli_query($con,$sql))
{
          echo "database created";
}
?>

Create table
<?php
$con=new mysqli("localhost","root","","student3");

$sql="CREATE TABLE details(roll INT(10) PRIMARY KEY AUTO_INCREMENT,
        Name VARCHAR(20) NOT  NULL,
                       Email  VARCHAR(20) NOT  NULL,
                             Website VARCHAR(20) NOT  NULL,
                             Gender VARCHAR(20) NOT  NULL,
                             Comment VARCHAR(20) NOT  NULL)";
                            
                             if(mysqli_query($con,$sql))
                             {
                                      echo "table created";
                             }

?>

Insert table
<?php
if(isset($_POST['submit']))
{
$n=$_POST['name'];
$e=$_POST['email'];
$w=$_POST['website'];
$c=$_POST['comment'];
$g=$_POST['gender'];
}

$con=new mysqli("localhost","root","","student3");

$sql= "INSERT INTO details(Name,email,website,comment,gender)VALUES('$n','$e','$w','$c','$g')";
if(mysqli_query($con,$sql))
{
          echo "data inserted";
}
else
{
          echo mysqli_error($con);
}
?>
IF YOU WANT TO TABLE IS ONLY RECORD WHEN COMPLETE DETAILS IS AVILABLE IN FORM
YOU ADD JUST ONE LINE BEFORE INSERT QUERY

<?php
$con=new mysqli("localhost","root","","student3");

$n=$e="";
if(isset($_POST['submit']))
{
$n=$_POST['name'];
$e=$_POST['email'];
$w=$_POST['website'];
$c=$_POST['comment'];
$g=$_POST['gender'];

if($n&&$e&&$w&&$g)
{
$sql= "INSERT INTO details(Name,email,website,comment,gender)VALUES('$n','$e','$w','$c','$g')";
if(mysqli_query($con,$sql))
{
          echo "data inserted";
}
else
{
          echo mysqli_error($con);
}
}
else{
         
}echo "Complete *required field";
}
}
mysqli_close($con);
?>
Fetch data
<html>
<head>
<style>
table,th,td
{
          border:1px solid blue;
}
th{
          background-color:red;
}
th,td{
          height:50px;
          width:90px;
}
</style>
</head>
<body>
<table border="1">
<tr><th colspan="8">view all records</th></tr>
<tr><td>Roll No.</td><td>Name</td>
<td>email</td><td>website</td>
<td>gender</td>
<td>edit</td>
<td>delete</td>
<td>details</td></tr>


<?php
$conn= new mysqli("localhost","root","","student3");
$sql="SELECT * FROM details";

$result=$conn->query($sql);


while($row=$result->fetch_assoc()){
          echo "<table border='1'>";
          echo "<tr><td>".$row['roll']."</td><td>".$row['Name']."</td>";
          echo "<td>".$row['Email']."</td>";
          echo "<td>".$row['Website']."</td>";
echo "<td>".$row['Gender']."</td>";
echo "<td>edit</td>
<td>delete</td>
<td>details</td></tr>";
}
echo "</table>";
?>

Monday, 15 July 2019

student project-2


<?php
$name= $f_name="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
        if(empty($_POST['s_name']))
        {
                $name="Name is required";
}
if(empty($_POST['f_name']))
        {
                $f_name="Name is required";

}
}
?>

<form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<table border='1' width="50%">
<tr><th align="center" bgcolor="pink"colspan="3" >Student Information </th></tr>
<tr><td>Student Name</td><td><input type="text" name="s_name">


<?php

echo $name;


 ?>
 </td></tr>
<tr><td>Father Name</td><td><input type="text" name="f_name">

<?php 

echo $f_name;

?>
</td></tr>
<tr><td>School Name</td><td><input type="text" name="school"></td></tr>
<tr><td>Roll No</td><td><input type="text" name="roll"></td></tr>
<tr><td>Class</td><td><select  name="s_class">
<option value='null'>Select class</option>
<option name='10'>10th</option>
<option name='9'>9th</option>
<option name='10'>8th</option>
</select>
</td></tr>
<tr><td colspan="3" align ="center"><input type="submit" name="submit" style="background:blue;color:white"></td></tr>
</table>
</form>

student project-1


<html>
<head>
<style>
table{
        border:2px solid black;
}
</style>
</head>
<body>
<table border='1' width="50%">
<tr><th align="center" bgcolor="pink"colspan="3" >Student Registration System</th></tr>
<tr><td>Student Name</td><td><input type="text" name="s_name"></td></tr>
<tr><td>Father Name</td><td><input type="text" name="f_name"></td></tr>
<tr><td>School Name</td><td><input type="text" name="school"></td></tr>
<tr><td>Roll No</td><td><input type="text" anme="roll"></td></tr>
<tr><td>Class</td><td><select  name="s_class">
<option value='null'>Select class</option>
<option name='10'>10th</option>
<option name='9'>9th</option>
<option name='10'>8th</option>
</select>
</td></tr>
<tr><td colspan="3" align ="center"><input type="submit" name="submit" style="background:blue;color:white"></td></tr>
</table>

</body>
</html>

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>";
?>