PHP Config.php file Using OOPS

Here i have Write Oops Config file in Core PHP 

  class Database 
      private $folder_name;
      private $host_name;
      private $user_name;
      private $password;
      private $db_name;
      private $con;
      private $result;
      function __construct()
if($_SERVER['HTTP_HOST'] == 'localhost'){  //(if we will use it in local server xampp)
              $this->folder_name = '/test/';
              $this->host_name = "";
              $this->user_name = "root";
              $this->password = "";
              $this->db_name = "test";
              $this->folder_name = "/test";  //(if we will use it in Hosting server)
              $this->host_name = "";
              $this->user_name = "sharique";
              $this->password = "sharique";
              $this->db_name ="test";
$this->con = mysql_connect($this->host_name, $this->user_name, $this->password)
          or die("Couldn't connect to the database".mysql_error());

public function execute($query){
          $this->result = mysql_query($query, $this->con);
public function getResult(){
          return mysql_fetch_assoc($this->result);
public function getResults(){      $return = array();      while ($row = mysql_fetch_assoc($this->result)) {          $return[]=$row;      }      return $return;  }  public function rowCount(){      return mysql_num_rows($this->result);  }  public function LastId() {     return mysql_insert_id(); }  public function affectedRows(){      return mysql_affected_rows();  }

 } else {
 $root = 'http//'.$_SERVER['HTTP_HOST'].$folder_name;
 $doc_root =$_SERVER['DOCUMENT_ROOT'].$folder_name;
 $css_root = $root. 'css/';
 $lib_root = $root.'lib/';
 $include_root = $root.'include/';
 $images_root = $root.'images/';
 $date=date('Y-m-d H:i:s');
 $modified_date=date('d-M-Y, D');


PHP Config page using mysqli

$servername =  'localhost'; $username  =   'root'; $password  =   ''; 

$dbname    =   'databasename';

$connection=mysqli_connect($servername,    $username, $password, "$dbname");
if(!$connection)         {           die('Could not Connect MySql Server:' .mysql_error());     } 

/*$mysqli = new mysqli("localhost","root","","databasename");  if ($mysqli->connect_errno) {     printf("Connect failed: %s\n", $mysqli->connect_error);     exit(); } */



<h2 class="title">Registration Info</h2>                     

<form method="POST" action="insert.php" name="insertform">                         <div class="input-group">                             
<input class="input--style-1" type="text" placeholder="NAME" name="name" id="name">                         
<div class="input-group">                            
 <h1>Show Checkboxes</h1> <br>                           
  <input type="checkbox" name="vcl[]" value="Bike">                             <label for="vcl"> I have a bike</label><br>                             <input type="checkbox" name="vcl[]" value="Car">                             <label for="vcl"> I have a car</label><br>                             <input type="checkbox" name="vcl[]" value="Boat">                             <label for="vcl"> I have a boat</label><br><br>                         </div>                         
<div class="row row-space">                             
<div class="col-2">                                 
<div class="input-group">                                    
 <input class="input--style-1 js-datepicker" type="text" placeholder="BIRTHDATE" id="birthday" name="birthday">                                     <i class="zmdi zmdi-calendar-note input-icon js-btn-calendar"></i>                                 </div>                            
<div class="col-2">                                
 <div class="input-group">                                     
<div class="rs-select2 js-select-simple select--no-search">                                         <select name="gender">                                            
 <option disabled="disabled" selected="selected">GENDER</option>                                             <option>S</option>                                             <option>M</option>                                             <option>F</option>                                             <option>O</option>                                        
<div class="select-dropdown"></div>                                     </div>                                 
<div class="col-2">                             <tr>                                 <!-- checked radio button -->                            
 <td align="left">User Gender : </td>                              
 <input type="radio" name="user_gender" value="Male"> Male                                                                
 <input type="radio" name="user_gender" value="Female"> Female                               <input type="radio" name="user_gender" value="Other"> Other                             </td>                           
 <div class="col-2">                               
  <div class="input-group">                               
                       <td>                                            <input type="checkbox" name="hobbies[]" value="cricket"/>Cricket                                        <input type="checkbox" name="hobbies[]" value="football"/>football                                        <input type="checkbox" name="hobbies[]" value="tenis"/>Tenis                                        <input type="checkbox" name="hobbies[]" value="vollyball"/>Vollyball                                    </td>                           
      </tr>                            </div>                        </div>                    </div>               
     <div class="input-group">                
     <div class="rs-select2 js-select-simple select--no-search">                         <select name="class">                             <option disabled="disabled" selected="selected">CLASS</option>                             <option>Class 1</option>            
                 <option>Class 2</option>                             <option>Class 3</option>                
         </select>                         <div class="select-dropdown"></div>                     </div>                 </div>                 <div class="row row-space">                     <div class="col-2">                         <div class="input-group">                             <input class="input--style-1" type="text" placeholder="REGISTRATION CODE" id="res_code" name="res_code">                         </div>                     </div>                 </div>                 <div class="p-t-20">                     <button name="send" id="send" class="btn btn--radius btn--green" type="submit">Submit</button>                 </div>             </form>             <br>             <?php              echo "<table border=1>";             echo "<tr>";             echo "<td>ID</td>";             echo "<td>NAME</td>";             echo "<td>DOB</td>";             echo "<td>Gen</td>";             echo "<td>Cls</td>";             echo "<td>RG No</td>";             echo "<td>Hb</td>";             echo "<td>CHK</td>";             echo "<td>Usr Gen</td>";             echo "<td colspan=2>Act</td>";             echo "</tr>";             echo "</thead>";              if ($regis = $connection-> query("SELECT * FROM registration ORDER BY id ASC")){                 $i =1;                 foreach ($regis as $registration) {                     ?>                     <tbody>                         <tr>                           <th scope="row"><?php echo $i++; ?></th>                           <td><?php echo $registration['name']; ?></td>                           <td><?php echo $registration['birthday']; ?></td>                           <td><?php echo $registration['gender']; ?></td>                           <td><?php echo $registration['class']; ?></td>                           <td><?php echo $registration['res_code']; ?></td>                           <td><?php echo $registration['hobbies']; ?></td>                           <td><?php echo $registration['vcl']; ?></td>                           <td><?php echo $registration['user_gender']; ?></td>                           <td> <a href="edit.php?id=<?php echo $registration['id']; ?>&edit=Y"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a> </td>                           &nbsp                           <td><a href="delete.php?id=<?php echo $registration['id']; ?>&del=y" onClick="return confirm('Do you really want to delete this ?');"><i class="fa fa-trash-o" aria-hidden="true"></i></a>                           </td>                       </tr>                   <?php } $regis->close(); }                     $connection->close();                    ?>               </tbody>           </table>       </div>   </div> </div> </div> <!-- Jquery JS--> <script src="vendor/jquery/jquery.min.js"></script> <!-- Vendor JS--> <script src="vendor/select2/select2.min.js"></script> <script src="vendor/datepicker/moment.min.js"></script> <script src="vendor/datepicker/daterangepicker.js"></script> <!-- Main JS--> <script src="js/global.js"></script> <script type="text/javascript"> /*$("#send").click(function(e){ var name = $("#name"); var birthday = $("#birthday"); var gender = $("gender"); //var class = $("class"); var res_code = $("res_code"); if(!name.val()){ $("#name").css("border", "1px solid red"); $("#name").focus(); e.preventDefault(); } if(!birthday.val()){ $("#birthday").css("border", "1px solid red"); $("#birthday").focus(); e.preventDefault(); } if(!gender.val()){ $("#gender").css("border", "1px solid red"); $("#gender").focus(); e.preventDefault(); } if(!res_code.val()){ $("#res_code").css("border", "1px solid red"); $("#res_code").focus(); e.preventDefault(); } */ //}); </script> </body><!-- This templates was made by Colorlib ( -->
include_once 'config.php';
$name =  $_POST['name'];
       $birthday =  $_POST['birthday'];
       $gender =  $_POST['gender'];
       $class = $_POST['class'];
       $res_code =  $_POST['res_code'];
       $a = $_POST['hobbies'];
       $hobbies = implode(",", $a);
       $c = $_POST['vcl'];
       $vcl = implode(",", $c);
       $user_gender = $_POST['user_gender'];

query ("INSERT INTO registration (name,birthday,gender,class,res_code,hobbies,vcl,user_gender) VALUES ('$name','$birthday','$gender','$class','$res_code','$hobbies','$vcl','$user_gender') ");       if($insert)         {         $msg="Inserted";         echo "alert('$msg');
";         header('Location:index.php');         }   }       else       {        $errormsg="Error !!! Coba Lagi !!";        echo "alert('$errormsg');";        header('Location:index.php');       } $connection->close(); ?>

include_once 'config.php';
 $b = $_POST['hobbies']; $hobbies=implode(",", $b); $d = $_POST['vcl']; $vcl=implode(",", $d); $user_gender = $_POST['user_gender'];

query ("UPDATE registration SET name='$name',vcl='$vcl', birthday='$birthday', gender='$gender', class='$class', res_code='$res_code', hobbies='$hobbies',user_gender='$user_gender' WHERE id='$id'");     //echo $update_query;die;     if($update_query)     {     echo " alert('Rows are updated successfully');
";     echo "window.location='index.php?msg=Sent sucessfully.';
";       $msg="Secessfully Updated";     //echo '';     //header('Location:index.php');     }   }   }   ?>   <?php     if(isset($_GET['id']))     {     $id = $_GET['id'];     $test_query = $connection->query ("SELECT * from registration WHERE id='$id'");     //print_r($test_query);die;     while($data_fetch = $test_query->fetch_array(MYSQLI_BOTH))     {       //print_r($data_fetch);die;       $name = $data_fetch['name'];       //print_r($name);die;       $birthday = $data_fetch['birthday'];       $gender = $data_fetch['gender'];       $class = $data_fetch['class'];       $res_code = $data_fetch['res_code'];       $a = $data_fetch['hobbies'];       $hobbies = explode(",",$a);       $c = $data_fetch['vcl'];       $vcl = explode(",",$c);       $user_gender = $data_fetch['user_gender'];       //print_r($user_gender);die;   ?> <h2>Updating Data</h2> <form action="" method="post" name="insertform">   <table>    <tr>      <td>Name</td>     <td>:</td>     <td><input type="text" name="name" required placeholder="name" value="<?php echo $name;?>"></td>    </tr>    <tr>      <td>DOB</td>     <td>:</td>     <td><input type="text" name="birthday" required placeholder="birthday" value="<?php echo $birthday;?>"></td>    </tr>     <tr>      <td>Gender</td>     <td>:</td>     <td>       <?php $test_gender = array("S","M","F","O" ); ?>       <select name="gender" required>         <?php foreach ($test_gender as $gender_val ) {           $select = "";           if($gender_val == $data_fetch["gender"]){             $select = "selected";           }         }          ?>         <option value="O"                      <?php if ($data_fetch['gender'] == 'O') echo 'selected="selected"'; ?>>O         </option>         <option value="M"                   <?php if ($data_fetch['gender'] == 'M') echo 'selected="selected"'; ?>>M         </option>         <option value="F"                 <?php if ($data_fetch['gender'] == 'F') echo 'selected="selected"'; ?>>F         </option>       </select>     </td>   </tr>   <tr>     <td>Hobbies</td>           <td>                <input type="checkbox" name="hobbies[]" value='cricket' / <?php if (in_array("cricket", $hobbies)){               echo "checked";              }else { echo "";} ?>>Cricket              <input type="checkbox" name="hobbies[]" value='football' / <?php if (in_array("football", $hobbies)){               echo "checked";              }else { echo "";} ?>>football              <input type="checkbox" name="hobbies[]" value='tenis' / <?php if (in_array("tenis", $hobbies)){               echo "checked";              } else { echo ""; } ?>>Tenis              <input type="checkbox" name="hobbies[]" value='vollyball' / <?php if (in_array("vollyball", $hobbies)){               echo "checked";              } else { echo ""; } ?>>Vollyball           </td>      </tr>     <tr>     <td>Vechile</td>           <td>                <input type="checkbox" name="vcl[]" value='bike' / <?php if (in_array("bike", $vcl)){               echo "checked";              } ?>>Bike              <input type="checkbox" name="vcl[]" value='car' / <?php if (in_array("car", $vcl)){               echo "checked";              } ?>>Car              <input type="checkbox" name="vcl[]" value='boat' / <?php if (in_array("boat", $vcl)){               echo "checked";              } ?>>Boat           </td>      </tr>     <!-- checked radio button -->     <tr>         <td align="left"> Usr Gender : </td>           <td>             <?php             $radio1 = "";             $radio2 = "";             $radio3 = "";             if($data_fetch["user_gender"] == "Male"){             $radio1 = "checked";             }elseif($data_fetch["user_gender"] == "Female"){             $radio2 = "checked";             }elseif ($data_fetch["user_gender"] == "Other") {               $radio3 = "checked";             }             ?>           <input type="radio" name="user_gender" value="Male" <?php echo $radio1; ?>/> Male                         <input type="radio" name="user_gender" value="Female" <?php echo $radio2; ?>/> Female           <input type="radio" name="user_gender" value="Other" <?php echo $radio3; ?>/> Other         </td>         </tr>    <tr>      <td>class</td>     <td>:</td>     <td><input type="text" name="class" required placeholder="" value="<?php echo $class;?>"></td>    </tr>    <tr>      <td>class</td>     <td>:</td>     <td><input type="text" name="res_code" required placeholder="" value="<?php echo $res_code;?>"></td>    </tr>   </table>     <input type="submit" name="update" value="Update"/>     <input type="button" name="cancel" value="cancel" onClick="window.location.href='index.php';" />    </p>   </form>   <?php } } ?> 

7 thoughts on “PHP Config.php file Using OOPS

  • September 8, 2022 at 5:16 am

    I was very happy to discover this site. I wanted to thank you for ones time just for this fantastic read!! I definitely really liked every bit of it and i also have you saved as a favorite to see new things on your site.

  • September 8, 2022 at 7:35 pm

    my friends from work and I have been dreaming about. The niche of up to date info here on the network is beneficial and helpful and is going to help my kids and I in our studies while I am at work. It is obvious this forum gained a large amount of expertise about interesting topics and this page and other categories and information definitely show it. I’m not usually on the net most of the time however when I drinking a beer I am more often than not avidly searching for this sort of factual information and stuff closely related to it. When anyone gets a chance, have a look at my website. selling a home without a realtor in Conyers, StoneCrest GA 30094

  • September 10, 2022 at 5:39 pm

    Next time I read a blog, I hope that it wont fail me just as much as this particular one. I mean, Yes, it was my choice to read, however I actually believed you would have something useful to talk about. All I hear is a bunch of moaning about something you could fix if you werent too busy looking for attention.

  • September 20, 2022 at 1:13 am

    Itís difficult to find educated people for this topic, however, you seem like you know what youíre talking about! Thanks

  • November 6, 2022 at 3:30 pm

    hi!,I like your writing very a lot! percentage we keep up a correspondence extra
    approximately your article on AOL? I require an expert in this
    house to resolve my problem. May be that’s you! Having a look
    ahead to look you.


Leave a Reply

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