Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Wednesday, November 21, 2018

How can edit the data in MySql using core php ?

form.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//edit
if (isset($_REQUEST['edit_id']))
{
$eid=$_REQUEST['edit_id'];
$select="select * from tbl_user where id='$eid' ";
$ex=mysql_query($select);
$rec=mysql_fetch_array($ex);
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
     <tr>
         <td>name</td>
            <td><input type="text" name="name" value="<?php echo $res['name']; ?>"></td>
        </tr>
        <tr>
         <td>password</td>
            <td><input type="text" name="pass" value="<?php echo $res['password']; ?>"></td>
        </tr>
        <tr>
         <td>gender</td>
< td>
<?php 
    $gen=$rec['gender']; // gender is the database table coulmn name
     if($gen=='male')
      {

?>
            <input type="radio" name="gender" value="male" checked='checked'>male
             <input type="radio" name="gender" value="female">female

<?php 
}  
else  if($gen=='female')
{ ?>
 <input type="radio" name="gender" value="male">male
 <input type="radio" name="gender" value="female" checked='checked'>male
          
<?php 
}
else 
{

?>
<input type="radio" name="gender" value="male">male
   <input type="radio" name="gender" value="female">female

<?php 
}?>
< /td>
        </tr>
        <tr>
         <td>hobby</td>
            <td>
<?php 
    $ex=$rec['hobby'];
    $h=explode("," , $ex);

if (isset($_REQUEST['edit_id']))
{
        if($h[0]=='cricket')
        { ?>
             <input type="checkbox" name="chk[]" value="cricket" checked='checked'>cricket
            <?php
              }
               else
               { ?>
           
            <input type="checkbox" name="chk[]" value="cricket">cricket
<?php 
}  
 if($h[0]=='hockey' || $h[1]=='hockey' )
{ ?>
  <input type="checkbox" name="chk[]" value="hockey" checked='checked'>hockey
            <?php }
               else
               { ?>
               <input type="checkbox" name="chk[]" value="hockey">hockey

<?php }}
else
{
?>
 <input type="checkbox" name="chk[]" value="cricket">cricket
<input type="checkbox" name="chk[]" value="hockey">hockey
<?php }
?>

< /td>
        </tr>
        <tr>
         <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>


View.php---edit link

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

$s="select * from user";//select all records from user table
$ex=mysql_query($s);


?>
<html>
<head>
<style type="text/css">
table th{ background:#F93; color:white;}
table td{ background:#FC9;}
</style>
</head>
<body>
<form method="post">
<table  align="center">
<tr>
<th>id</th>
    <th>name</th>
    <th>pass</th>
    <th>gender</th>
    <th>hobby</th>\
< th>action</th>
    
</tr>
<?php
while ($ft=mysql_fetch_array($ex))   / /fetch the records using  mysql_fetch_array with  while loop
{
?>
<tr>
<td><?php echo $ft['id']; ?></td>
    <td><?php echo $ft['name']; ?></td>
    <td><?php echo $ft['pass']; ?></td>
    <td><?php echo $ft['gender']; ?></td>
    <td><?php echo $ft['hobby']; ?></td>
    <td><a href="form.php ? edit_id=<?php echo $ft['id']; ?>">edit</a></td>
</tr>
<?php
}
?>

</table>
</form>
</body>
</html>

How can edit the data in MySql using core php ?

form.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//edit
if (isset($_REQUEST['edit_id']))
{
$eid=$_REQUEST['edit_id'];
$select="select * from tbl_user where id='$eid' ";
$ex=mysql_query($select);
$rec=mysql_fetch_array($ex);
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
     <tr>
         <td>name</td>
            <td><input type="text" name="name" value="<?php echo $res['name']; ?>"></td>
        </tr>
        <tr>
         <td>password</td>
            <td><input type="text" name="pass" value="<?php echo $res['password']; ?>"></td>
        </tr>
        <tr>
         <td>gender</td>
< td>
<?php 
    $gen=$rec['gender']; // gender is the database table coulmn name
     if($gen=='male')
      {

?>
            <input type="radio" name="gender" value="male" checked='checked'>male
             <input type="radio" name="gender" value="female">female

<?php 
}  
else  if($gen=='female')
{ ?>
 <input type="radio" name="gender" value="male">male
 <input type="radio" name="gender" value="female" checked='checked'>male
          
<?php 
}
else 
{

?>
<input type="radio" name="gender" value="male">male
   <input type="radio" name="gender" value="female">female

<?php 
}?>
< /td>
        </tr>
        <tr>
         <td>hobby</td>
            <td>
<?php 
    $ex=$rec['hobby'];
    $h=explode("," , $ex);

if (isset($_REQUEST['edit_id']))
{
        if($h[0]=='cricket')
        { ?>
             <input type="checkbox" name="chk[]" value="cricket" checked='checked'>cricket
            <?php
              }
               else
               { ?>
           
            <input type="checkbox" name="chk[]" value="cricket">cricket
<?php 
}  
 if($h[0]=='hockey' || $h[1]=='hockey' )
{ ?>
  <input type="checkbox" name="chk[]" value="hockey" checked='checked'>hockey
            <?php }
               else
               { ?>
               <input type="checkbox" name="chk[]" value="hockey">hockey

<?php }}
else
{
?>
 <input type="checkbox" name="chk[]" value="cricket">cricket
<input type="checkbox" name="chk[]" value="hockey">hockey
<?php }
?>

< /td>
        </tr>
        <tr>
         <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>

View.php---edit link

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

$s="select * from user";//select all records from user table
$ex=mysql_query($s);


?>
<html>
<head>
<style type="text/css">
table th{ background:#F93; color:white;}
table td{ background:#FC9;}
</style>
</head>
<body>
<form method="post">
<table  align="center">
<tr>
<th>id</th>
    <th>name</th>
    <th>pass</th>
    <th>gender</th>
    <th>hobby</th>\
< th>action</th>
    
</tr>
<?php
while ($ft=mysql_fetch_array($ex))   / /fetch the records using  mysql_fetch_array with  while loop
{
?>
<tr>
<td><?php echo $ft['id']; ?></td>
    <td><?php echo $ft['name']; ?></td>
    <td><?php echo $ft['pass']; ?></td>
    <td><?php echo $ft['gender']; ?></td>
    <td><?php echo $ft['hobby']; ?></td>
    <td><a href="form.php ? edit_id=<?php echo $ft['id']; ?>">edit</a></td>
</tr>
<?php
}
?>

</table>
</form>
</body>
</html>

Delete data using core php ?


<?php
 if(isset($_REQUEST['del_id']))
 {
    $del=$_REQUEST['del_id'];
     $de="delete from user where uid='$del'";
    $ex=mysql_query($del);     header("location:view.php");
 }


?>
< html>
< body>
<form method="post" name="form1" >
< table width="200" align="center" class="frm_tbl">
  <tr>
    <td>Uid</td>
    <td>Name</td>
    <td>Password</td>
    <td>Gender</td>
    <td>Hobby</td>
  </tr>
<?php
while($r = mysql_fetch_array($ex))
{
?>
  <tr>
     <td><?php echo $r['uid']; ?></td>
    <td><?php echo $r['name']; ?></td>
    <td><?php echo $r['password']; ?></td>
    <td><?php echo $r['Gender']; ?></td>
    <td><?php echo $r['Hobby']; ?></td>
  <td><a href="view.php?del_id=<?php echo $r['uid']; ?>">delete</td>
  </tr>
<?php
}
?>
< /table>
</form>



How can fetch the records in MySQL using php?

Create  a  form.php  for the inserting data & view.php for the fetching data in the  Data base

  • Fetching Records  in the database using Mysql_fetch_array ( ) Function.
  • Select Command use for the fetching data in database.
       make a form.php for inserting data & below view.php for fetch the records

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

//insert data in database using submit button request
if (isset($_REQUEST['submit']))
{
$n=$_REQUEST['name'];
$p=$_REQUEST['pass'];
$g=$_REQUEST['gender'];
$h=$_REQUEST['chk'];
if ($h)
{
$ch=implode(",",$h);//implode is a string function that are implode a multipal array value like chk[];
}
$ins="insert into user(name,pass,gender,hobby) values('$n','$p','$g','$ch')";
$ex=mysql_query($ins);
header ("location:view.php");//redirect the page on view.php
}
?>
<html>
<head>
<title>insert the data</title>
</head>
<body>
<form method="post">
    <table border="1" align="center">
     <tr>
         <td>name</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
         <td>password</td>
            <td><input type="text" name="pass"></td>
        </tr>
        <tr>
         <td>male</td>
            <td><input type="radio" name="gender" value="male">male<input type="radio" name="gender" value="female">female</td>
        </tr>
        <tr>
         <td>hobby</td>
            <td><input type="checkbox" name="chk[]" value="cricket">cricket<input type="checkbox" name="chk[]" value="hockey">hockey</td>
        </tr>
        <tr>
         <td colspan="2"><input type="submit" name="submit" value="submit"></td>
        </tr>
    </table>
    </form>
</body>
</html>

View.php for fetching data

<?php
mysql_connect("localhost","root","");
mysql_select_db("project");

$s="select * from user";//select all records from user table
$ex=mysql_query($s);


?>
<html>
<head>
<style type="text/css">
table th{ background:#F93; color:white;}
table td{ background:#FC9;}
</style>
</head>
<body>
<form method="post">
<table  align="center">
<tr>
<th>id</th>
    <th>name</th>
    <th>pass</th>
    <th>gender</th>
    <th>hobby</th>
    
</tr>
<?php
while ($ft=mysql_fetch_array($ex))   / /fetch the records using  mysql_fetch_array with  while loop
{
?>
<tr>
<td><?php echo $ft['id']; ?></td>
    <td><?php echo $ft['name']; ?></td>
    <td><?php echo $ft['pass']; ?></td>
    <td><?php echo $ft['gender']; ?></td>
    <td><?php echo $ft['hobby']; ?></td>
</tr>
<?php
}
?>

</table>
</form>
</body>
</html>

Output on a Browser:-