How to Search/Find the saved Mysql Data/Record

<!doctype html>
 <?php  
   /*-----------------------------------CONNECTIVITY CODE-----------------------------------*/
     error_reporting(E_ERROR | E_PARSE);      //optional,to remove warning messages.
     $conn=mysqli_connect("localhost","root","","codershelpline");
        if ($conn)
          {
           echo "database connected successfully","<br>";
          }
        else
          {
           die("Connection Aborted:" . mysqli_connect_error());
          }
    
/*-------------------------------------SEARCH CODE------------------------------------*/
$SearchBx1=$_REQUEST['SearchBx'];
if(isset($_REQUEST['BtnSrc']))
{			
   $query2="select * from chlsave where TxtSlno4='$SearchBx1'";
   $result=mysqli_query($conn,$query2);
  
   while($row1=mysqli_fetch_array($result))
  {
    $TxtSlno3=$row1['TxtSlno4'];
    $TxtSname3=$row1['TxtSname4'];
    $TxaAddr3=$row1['TxaAddr4'];
    $Rdbsex3=$row1['Rdbsex4'];
    $TxtUname3=$row1['TxtUname4'];
    $TxtPassword3=$row1['TxtPassword4'];
    $DtpDob3=$row1['DtpDob4'];
    $TxtMobno3=$row1['TxtMobno4'];
    $TxtEmail3=$row1['TxtEmail4'];	
    $CmbSecQues3=$row1['CmbSecQues4'];
    $TxtSecAns3=$row1['TxtSecAns4'];
    $ChkCricket3=$row1['ChkCricket4'];	
    $ChkDance3=$row1['ChkDance4'];
    $ChkMusic3=$row1['ChkMusic4'];	
    $TxtRem3=$row1['TxtRem4'];  
  }
}		
?> 
   
<!--------------------------------HTML DESIGN CODE------------------------------------->    
<html>
   <head>
      <title>Codershelpline Code for display html value</title>
   </head>
   <body>
      <form name="form1" id="form2" action="#" method="post" >
	 <center>
	    <fieldset style="width: 600px">				
		<legend>Create New Student Account</legend>
		   <table>
		      <tr>
			  <td>Serial No.</td>
			  <td>:</td>
			  <td><input type="text" name="TxtSlno" value="<?php echo $TxtSlno3;?>"></td>
			  <td>Search Box</td>
			  <td>
			     <select name="SearchBx" id="SearchBx">									
				<option>---Select---</option>
				<?php
				   $res=mysqli_query($conn,"select TxtSlno4 from chlsave");
				      while($row=mysqli_fetch_array($res))
				      {
				?>
					<option value="<?php echo $row['TxtSlno4'];?>"><?php echo 
                                           $row['TxtSlno4'];?></option>
				<?php
				      }
				?>
                             </select>
			  </td>
		      </tr>
		      <tr>
			  <td>Student Name</td>
			  <td>:</td>
			  <td><input type="text" name="TxtSname" value="<?php echo $TxtSname3;?>">
                          </td>
		      </tr>
		      <tr>
			  <td>Address</td>
			  <td>:</td>
			  <td>
			    <textarea cols="35" rows="5" name="TxaAddr"><?php echo $TxaAddr3;?>
                            </textarea>							
			  </td>
		       </tr>
		       <tr>
			  <td>Sex</td>
			  <td>:</td>
		          <td>				  
			     <?php											
				if($Rdbsex3==="Male")
				{
				   $Gen1="checked";
				}	
				if($Rdbsex3==="Female")
				{
				   $Gen2="checked";
				}
				if($Rdbsex3==="Other")
				{
				   $Gen3="checked";
				}
			      ?>				  
		              <input type="radio" name="Rdbsex" id="RdbMale" <?php echo $Gen1;?> 
                                 value="Male">Male
		              <input type="radio" name="Rdbsex" id="RdbFemale" <?php echo $Gen2;?> 
                                 value="Female">Female
		              <input type="radio" name="Rdbsex" id="RdbOther" <?php echo $Gen3;?>
                                 value="Other">Other
		          </td>

		       </tr>						
		       <tr>
			  <td>User Name</td>
			  <td>:</td>
			  <td><input type="text" name="TxtUname" value="<?php echo $TxtUname3;?>">
                          </td>
		       </tr>
		       <tr>
			  <td>Password</td>
			  <td>:</td>
			  <td><input type="password" name="TxtPassword" value="<?php echo 
                             $TxtPassword3;?>"></td>
		       </tr>
		       <tr>
			  <td>Confirm Password</td>
			  <td>:</td>
			  <td><input type="password" name="TxtCpassword" value="<?php echo 
                             $TxtCpassword3;?>"></td>
		       </tr>
		       <tr>
		          <td>DOB</td>
			  <td>:</td>
			  <td><input type="date" name="DtpDob" value="<?php echo $DtpDob3;?>"></td>
		       </tr>
		       <tr>
			  <td>Mobile No.</td>
			  <td>:</td>
			  <td><input type="Number" name="TxtMobno" value="<?php echo $TxtMobno3;?>">
                          </td>
		       </tr>
		       <tr>
			  <td>Email</td>
			  <td>:</td>
			  <td><input type="text" name="TxtEmail" value="<?php echo $TxtEmail3;?>">
                          </td>
		       </tr>					
		       <tr>
			  <td>Security Questions</td>
			  <td>:</td>
			  <td>		  
			     <?php										
				if($CmbSecQues3==="What is Your Favourite Book")
				{
				   $SecQues1="selected";
				}
				if($CmbSecQues3==="What is Your Favourite Teacher")
				{
				   $SecQues2="selected";
				}
				if($CmbSecQues3==="What is Your Favourate Place")
				{
				   $SecQues3="selected";
				}
				if($CmbSecQues3==="What is Your Favourate Pets")
				{
				   $SecQues4="selected";
				}
			     ?>			  
                             <select name="CmbSecQues">
                                <option value="Choose One">Choose One</option>
                                <option <?php echo $SecQues1;?> value="What is Your Favourite Book">
                                   What is Your Favourite Book</option>
                                <option <?php echo $SecQues2;?> value="What is Your Fav. Teacher">
                                   What is Your Favourite Teacher</option>
                                <option <?php echo $SecQues3;?> value="What is Your Favourate Place">
                                   What is Your Favourate Place</option> 
                                <option <?php echo $SecQues4;?> value="What is Your Favourate Pets">
                                   What is Your Favourate Pets</option>
                             </select>
			  </td>
		     </tr>
		     <tr>
			<td>Security Answer</td>
			<td>:</td>
			<td><input type="text" name="TxtSecAns" value="<?php echo $TxtSecAns3;?>">
                        </td>
		     </tr>
		     <tr>
			<td>Hobbies</td>
			<td>:</td>
			<td>			
			   <?php										
				if($ChkCricket3==="Cricket")
				{
				   $Ckt="checked";
				}
				if($ChkDance3==="Dance")
				{
				   $Dnc="checked";
				}
				if($ChkMusic3==="Music")
				{
				   $Msc="checked";
				}
			   ?>				
			   <input type="checkbox" name="ChkCricket" <?php echo $Ckt;?> value=
                              "Cricket">Cricket
			   <input type="checkbox" name="ChkDance" <?php echo $Dnc;?> value=
                              "Dance">Dance
			   <input type="checkbox" name="ChkMusic" <?php echo $Msc;?> value=
                              "Music">Music			   
			</td>
		     </tr>
		     <tr>
			<td>Remarks</td>
			<td>:</td>
			<td><input type="text" name="TxtRem" value="<?php echo $TxtRem3;?>"></td>
		     </tr>
		     <tr>
			<td></td>
			<td></td>
			<td><input type="submit" name="BtnSave" value="Save">
			    <input type="reset" name="BtnReset" value="Reset">
			    <input type="submit" name="BtnDel" value="Delete">
			    <input type="submit" name="BtnSrc" value="Search">
			    <input type="submit" name="BtnUpd" value="Update">
			</td>
		     </tr>

		  </table>
	      </fieldset>
            </center>
	  </form>
        </body>
      </html>

How to Display/Print Image from MySql Database using Php

<?php
     error_reporting(E_ERROR | E_PARSE);	
     $conn=mysqli_connect("localhost","root","","codershelpline");        
	if (!$conn)
          {
           die("Connection Aborted:" . mysqli_connect_error());
          }

 	$imageid2=$_REQUEST['imageid1'];
 	 	 
 	if(isset($_REQUEST['simage']))
          {
   	     $store="select * from chlsave where imageid3='$imageid2'";	
   	     $result=mysqli_query($conn,$store);

   	     while ($row=mysqli_fetch_array($result))
   	       {
   		 echo '<img height="300" width="300" src="data:image;base64,'.$row[1].'">'; 
   	       }
          }
?>

<!DOCTYPE html>
<html>
<head>
     <title></title>
</head>
<body>
    <form action="" method="post" enctype="multipart/form-data">
       <center>
          <table>				
             <tr>
                <td>Image Id</td>
		<td>:</td>
		<td>
		    <input type="text" name="imageid1">
		</td>
	     </tr>
				
	     <tr>
		<td></td>
		<td></td>
		<td>
		    <input type="submit" name="simage" value="Search Image">
		    <input type="reset" name="rst" value="Reset">								
		</td>						
	     </tr>
               
	  </table>
       </center>		
     </form>
  </body>
</html>

/* NB:
Database name:codershelpline. Table name:chlsave. Here a Field Name:imageid3, is a primarykey field on the basis of which image is searched.
In the code $row[1] where 1 is the index value of image field in the MySql Database(i.e. 2nd column of MySql database which is started as 0,1...).

The Program code 'src="data:image;base64' is used to display image. */

 568 total views,  1 views today

Categories: Php

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.