Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

22. Advanced Database Features

Lesson 19 of 29 in the free PHP Programming notes on Siksha Sarovar, written by Rohit Jangra.

Uploading Images into Database

Steps

  1. HTML file upload form
  2. Store image in folder
  3. Save image path in database

HTML Form

<form method="post" enctype="multipart/form-data">
<input type="file" name="img">
<input type="submit" name="upload">
</form>

PHP Code

$img = $_FILES['img']['name'];
$tmp = $_FILES['img']['tmp_name'];

move_uploaded_file($tmp, "uploads/".$img);

mysqli_query($conn, "INSERT INTO images(img) VALUES('$img')");

---

Downloading / Displaying Images from Database

$result = mysqli_query($conn, "SELECT img FROM images");

while($row = mysqli_fetch_assoc($result)){
   echo "<img src='uploads/".$row['img']."' width='100'>";
}
Exam Tip: Images are usually stored as file paths, not binary data.

---

Registration Form with Validation

Fields

  • Name
  • Email
  • Password

PHP Validation Example

if(empty($email)){
   echo "Email Required";
}

Insert Query

mysqli_query($conn,
"INSERT INTO users(name,email,password)
VALUES('$name','$email','$pass')");

---

Login Form with Validation

$sql = "SELECT * FROM users WHERE email='$email' AND password='$pass'";
$result = mysqli_query($conn, $sql);

if(mysqli_num_rows($result)==1){
   echo "Login Success";
}else{
   echo "Invalid Login";
}
Exam Line: Registration stores data, login verifies credentials.

---

Pagination (Paging)

Pagination is used to display limited records per page.

Formula

$limit = 5;
$offset = ($page - 1) * $limit;

Query

SELECT * FROM users LIMIT $limit OFFSET $offset;
Exam Definition: Pagination improves performance by limiting records per page.

---

Sorting Records

Sorting is done using ORDER BY.

SELECT * FROM users ORDER BY name ASC;
SELECT * FROM users ORDER BY id DESC;

---

Advantages of PHP with MySQL

  • Easy database handling
  • Fast development
  • Secure with prepared statements
  • Widely supported
  • Scalable applications