View / Select OOP

1 comments
<?php
include('Session.php');

include_once ('all.php');
$data = new Databases;
 
 ?>
 <!DOCTYPE html>
 <html>
      <head>
           <title>Webslesson Tutorial | Select or Fetch Data from Mysql Table using OOPS in PHP</title>
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
      </head>
      <body>
           <br /><br />
           <div class="container" style="width:700px;">

                <br />
                <div class="table-responsive">
                     <table class="table table-bordered">
                          <tr>
                               <td width="30%">ID</td>
                               <td width="50">Name</td>
                               <td width="10%">Username</td>
                               <td width="10%">Password</td>
                          </tr>
                          <?php
                          $post_data = $data->select('academic');
                          foreach($post_data as $row)
                          {
                          ?>
                          <tr>
                               <td><?php echo $row["id"]; ?></td>
                               <td><?php echo substr($row["name"], 0, 200); ?></td>
                               <td><?php echo substr($row["username"], 0, 200); ?></td>
                               <td><?php echo substr($row["pw"], 0, 200); ?></td>
                               <td><a href="update.php?id=<?php echo $row["id"]; ?>">Edit</a></td>
                               <td><a href="deloop.php?id=<?php echo $row["id"]; ?>">Delete</a></td>
                          </tr>
                          <?php
                          }
                          ?>
                     </table>
                </div>

<h3><a href="Logout.php"> Logout </a></h3>

           </div>
      </body>
 </html>

Read More »

Insert With Folder Img

0 comments
<?php

include_once("db.php");
$insertdata=new Databases();


if(isset($_POST['insert']))
{

    $name = $_POST['name'];
    $email = $_POST['email'];
    $num = $_POST['num'];
    $msg = $_POST['msg'];

$target_dir = "flimg/";
$target_file = $target_dir . basename($_FILES["fileName"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    $check = getimagesize($_FILES["fileName"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }

// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileName"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPRG") {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileName"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileName"]["name"]). " has been uploaded.";
$sql=$insertdata->insert($name,$email,$num,$msg);
if (isset($_REQUEST['email']))  {

//Email information
$admin_email = "kistlakall@gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['name'];
$comment = $_REQUEST['msg'];

//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
}
    } else {
        echo "Sorry, there was an error uploading your Data and File.";
    }
  }
 
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP INSERT DATA </title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>
        <form action="" method="post" enctype="multipart/form-data">

            Name <input type="text" name="name"><br><br>

            Email <input type="email" name="email"><br><br>

            Number <input type="text" name="num"><br><br>

            Message <input type="text" name="msg"><br><br>

            Upload <input type="file" name="fileName"><br><br>

            <input type="submit" name="insert" value="Add Data To Database">

        </form>

    </body>

</html>

Read More »

Insert OOP

1 comments
<?php

 include_once ('all.php');  
 $data = new Databases;
 $success_message = '';
 if(isset($_POST["submit"]))
 {
      $insert_data = array(
           'name'     =>     mysqli_real_escape_string($data->con, $_POST['name']),
           'username'          =>     mysqli_real_escape_string($data->con, $_POST['username']),
           'pw'          =>     mysqli_real_escape_string($data->con, $_POST['password'])
      );
      if($data->insert('academic', $insert_data))
      {
           $success_message = 'Post Inserted';
      }      
 }
 ?>
 <!DOCTYPE html>
 <html>
      <head>
           <title>Insert data into Table using OOPS in PHP</title>
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
      </head>
      <body>
           <br /><br />
           <div class="container" style="width:700px;">
                <form method="post">
                     <label>Name</label>
                     <input type="text" name="name" class="form-control" />
                     <br />
                     <label>Username</label>
                     <input type="text" name="username" class="form-control" />
                     <br />
<label>Password</label>
                     <input type="password" name="password" class="form-control" />
                     <br />
                     <input type="submit" name="submit" class="btn btn-info" value="Submit" />
                     <span class="text-success">
                     <?php
                     if(isset($success_message))
                     {
                          echo $success_message;
                     }
                     ?>
                     </span>
                </form>
           </div>
      </body>
 </html>

Read More »

Session OOP

0 comments
<?php

include_once ('all.php');
$sesdata = new Databases;

session_start();
$user_check=$_SESSION['login_user'];

$row=$sesdata->ses($user_check);

$login_session=$row['username'];
if(!isset($_SESSION['login_user']))
{
header('location: Login.php');
exit;
}

?>

Read More »

Login Web OOP

0 comments
<?php

include_once ('all.php');
$logindata = new Databases;

session_start();
$error='';

if(isset($_POST['login']))
{
if(empty($_POST['username']) || empty($_POST['password']))
{
$error = "Username Or Password Is Empty";
}
else
{
$username=$_POST['username'];
$password=$_POST['password'];

$rows=$logindata->login($username,$password);

if($rows==1)
{
$_SESSION['login_user']=$username;
header('location:select.php');
}
else
{
$error="Invalid Username Or Password";
}

}
}

?>

Read More »

Login OOP

0 comments
<?php
include('LoginWeb.php');
?>

<html>

<head>

</head>

<body>

<center>
<form action="" method="POST">
Username : <input type="text" name="username"> <br><br>
Password : <input type="password" name="password"> <br><br>
<input type="submit" name="login" value="Login"> <br><br>
<?php echo $error; ?>
</form>
</center>

</body>
</html>

Read More »

OOP DB

0 comments
<?php  

 class Databases{
      public $con;
      public function __construct()
      {
           $this->con = mysqli_connect("localhost", "root", "", "portal");
           if(!$this->con)
           {
                echo 'Database Connection Error ' . mysqli_connect_error($this->con);
           }
      }

      public function insert($table_name, $data)
      {
           $string = "INSERT INTO ".$table_name." (";          
           $string .= implode(",", array_keys($data)) . ') VALUES (';          
           $string .= "'" . implode("','", array_values($data)) . "')";
           if(mysqli_query($this->con, $string))
           {
                return true;
           }
           else
           {
                echo mysqli_error($this->con);
           }
      }

  public function insertsingle($name,$username,$password)
      {
           $string = "INSERT INTO academic (name,username,pw) VALUES ('$name','$username','$password')";
           $rsint=mysqli_query($this->con, $string);
  return $rsint;
      }

      public function select($table_name)
      {
           $array = array();
           $query = "SELECT * FROM ".$table_name."";
           $result = mysqli_query($this->con, $query);
           while($row = mysqli_fetch_assoc($result))
           {
                $array[] = $row;
           }
           return $array;
      }
 
  public function viewforup($id)
{
$vfu="SELECT * FROM academic WHERE id='$id' ";
$rs = mysqli_query($this->con, $vfu);
$vfurow=mysqli_fetch_array($rs);
return $vfurow;
}
 
  public function update($id,$name,$username,$password)
{
$up="UPDATE academic SET name='$name' , username='$username' , pw='$password' WHERE id='$id' ";
$uprs = mysqli_query($this->con, $up);
return $uprs;
}

  public function del($id)
{
$deldel="DELETE FROM academic WHERE id=$id";
$delrs = mysqli_query($this->con, $deldel);
return $delrs;
}

  public function login($username,$password)
{
$loginquery="SELECT * FROM academic WHERE username='$username' AND pw='$password' ";
$loginrs = mysqli_query($this->con, $loginquery);
$rows=mysqli_num_rows($loginrs);
return $rows;
}

  public function ses($user_check)
{
$sesrs="SELECT username FROM academic WHERE username='$user_check' ";
$sesquery = mysqli_query($this->con, $sesrs);
$rowrs=mysqli_fetch_assoc($sesquery);
return $rowrs;
}

  public function checkun($username)
{
$checkquery="SELECT * FROM academic WHERE username='$username' ";
$loginrs = mysqli_query($this->con, $checkquery);
$rowc=mysqli_num_rows($loginrs);
return $rowc;
}
 
  public function imgreg($fname,$username,$password,$filename,$filepath,$filetype)
   {
   $imginsert = "INSERT INTO academic (fname,username,pw,img_name,img_path,img_type) VALUES ('$fname','$username','$password','$filename','$filepath','$filetype')";
   $imgquery=mysqli_query($this->con, $imginsert);
   return $imgquery;
   }
 
 }
 ?>

Read More »

Tweet Now !!

Recommend us on Google!