Skip to content

Commit b942f86

Browse files
committed
Initial Commit
0 parents  commit b942f86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3167
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

1/config.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$dbhost = "localhost";
4+
$dbuser = "root";
5+
$dbpass = "root";
6+
$dbname = "test_db";
7+
8+
//Connect to MySQL Server
9+
$con = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
10+
11+
// if(!$con)
12+
// echo "Connection Error.";
13+
// else
14+
// echo "Database Connection Successfully.";
15+
16+
17+
// $con -> close();

1/index.php

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
require_once "config.php";
4+
5+
$sql = "select * from subjects";
6+
$subjects = mysqli_query($con,$sql);
7+
8+
$sql = "select distinct locality from students";
9+
$localities = mysqli_query($con,$sql);
10+
// print_r( mysqli_fetch_re $localities);
11+
12+
if(isset($_POST['submit'])){
13+
$keyword = $_POST['keyword'];
14+
$locality = $_POST['locality'];
15+
$subject= implode(",",$_POST['subject']);
16+
17+
18+
$sql = "select * from students where name like '%$keyword%'";
19+
if($locality) $sql .= " and locality = '$locality'";
20+
21+
22+
if($subject) $sql .= " and id in( SELECT student_id FROM `student_subject` WHERE subject_id in ($subject))";
23+
24+
25+
$query = mysqli_query($con,$sql);
26+
}
27+
28+
function get_subject($con,$student_id){
29+
$sql = "SELECT name FROM `subjects` WHERE id in ( select `subject_id` from `student_subject` where `student_id` = $student_id )";
30+
$list = mysqli_query($con,$sql);
31+
32+
33+
while( $subject = $list->fetch_row() ){
34+
echo $subject[0] ."<br/>";
35+
}
36+
37+
}
38+
?>
39+
40+
<center>
41+
<a href="index.php"> Search</a> | <a href="students.php"> Add Student</a> | <a href="subjects.php"> Add Subject</a>
42+
</center>
43+
<h1>Search Students</h1>
44+
<form action="" method="post">
45+
46+
Search Keyword: <input type="text" name="keyword" /> Locality: <select name="locality" id="">
47+
<option value ="" >Select </option>
48+
<?php
49+
50+
while( $subject = $localities->fetch_row() ){
51+
?>
52+
<option value ="<?php echo $subject[0] ; ?>" > <?php echo $subject[0]; ?></option>
53+
<?php
54+
}
55+
?>
56+
</select> Subjects :
57+
<?php
58+
foreach($subjects as $subject){
59+
?>
60+
<label><input type="checkbox" name="subject[]" value ="<?php echo $subject['id'] ; ?>" /> <?php echo $subject['name'] ; ?></label>
61+
<?php
62+
}
63+
?>
64+
<input type="submit" name="submit" value="Search">
65+
66+
</form>
67+
68+
<?php if(mysqli_num_rows($query)){ ?>
69+
<table border="1">
70+
<thead>
71+
<tr>
72+
<th>Photo</th>
73+
<th>Name</th>
74+
<th>Roll No</th>
75+
<th>Locality</th>
76+
<th>Subject</th>
77+
</tr>
78+
</thead>
79+
<?php
80+
while( $students = $query->fetch_row() ){
81+
?>
82+
<tr>
83+
<td><?php echo $students[4]?"<img width='50' height='50' src='$students[4]' />":""; ?></td>
84+
<td><?php echo $students[1]; ?></td>
85+
<td><?php echo $students[2]; ?></td>
86+
<td><?php echo $students[3]; ?></td>
87+
<td><?php get_subject($con,$students[0]); ?></td>
88+
89+
</tr>
90+
<?php
91+
}
92+
93+
?>
94+
</table>
95+
<?php } ?>

1/readme.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Super basic mysql connectivity
2+
3+
We'll learn php my sql connectiveity wrong way in this step. Just because it is easy to understand, we'll forget all the coding standards and vulnerabilities for sake of creating simplified code.
4+
5+
## Files:
6+
7+
**config.php**
8+
Holds all the global variables and database connections
9+
10+
**index.php**
11+
Search page with a seach form
12+
13+
**students.php**
14+
Student addition form
15+
16+
**subjects.php**
17+
subject addtition form

1/students.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
require_once "config.php";
4+
5+
if(isset($_POST['submit'])){
6+
7+
$name = $_POST['name'];
8+
$rollno = $_POST['rollno'];
9+
$locality = $_POST['locality'];
10+
$subjects = $_POST['subject'];
11+
$image = '';
12+
// print_r($subject);exit;
13+
14+
$target_dir = "uploads/";
15+
$target_file = $target_dir . $_FILES["image"]["name"];
16+
$tempname = $_FILES["image"]["tmp_name"];
17+
18+
19+
if (move_uploaded_file($tempname, $target_file)) {
20+
$image = $target_file;
21+
}
22+
23+
$sql = "insert into students( `name` ,`rollno`,`locality`,`image` ) values ('$name','$rollno','$locality','$image')";
24+
mysqli_query($con,$sql);
25+
$student_id = $con->insert_id;
26+
27+
foreach($subjects as $subject){
28+
$sql = "insert into student_subject( `student_id`,`subject_id`) values ('$student_id','$subject')";
29+
mysqli_query($con,$sql);
30+
}
31+
32+
33+
34+
}
35+
36+
$sql = "select * from subjects";
37+
$subjects = mysqli_query($con,$sql);
38+
39+
?>
40+
41+
<center>
42+
<a href="index.php"> Search</a> | <a href="students.php"> Add Student</a> | <a href="subjects.php"> Add Subject</a>
43+
</center>
44+
45+
<h1>Add Students</h1>
46+
<form action="" method="post" enctype="multipart/form-data">
47+
<label>Name: </label><input type="text" name="name"/><br/>
48+
<label>Roll No: </label><input type="number" name="rollno" /><br/>
49+
<label>Locality: </label><input type="text" name="locality" /><br/>
50+
<label>Image: </label><input type="file" name="image"/><br/>
51+
<label>Subjects: </label>
52+
<?php
53+
foreach($subjects as $subject){
54+
?>
55+
<label><input type="checkbox" name="subject[]" value ="<?php echo $subject['id'] ; ?>" /> <?php echo $subject['name'] ; ?></label>
56+
<?php
57+
}
58+
?>
59+
<br/>
60+
<input type="submit" name="submit" />
61+
</form>

1/subjects.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
require_once "config.php";
4+
5+
if(isset($_POST['submit'])){
6+
7+
$name = $_POST['name'];
8+
$marks = $_POST['marks'];
9+
10+
$image = '';
11+
12+
$target_dir = "uploads/";
13+
$target_file = $target_dir . $_FILES["image"]["name"];
14+
$tempname = $_FILES["image"]["tmp_name"];
15+
16+
17+
if (move_uploaded_file($tempname, $target_file)) {
18+
$image = $target_file;
19+
}
20+
21+
$sql = "insert into subjects( `name` ,`marks`,`image` ) values ('$name','$marks','$image')";
22+
mysqli_query($con,$sql);
23+
}
24+
25+
26+
?>
27+
<center>
28+
<a href="index.php"> Search</a> | <a href="students.php"> Add Student</a> | <a href="subjects.php"> Add Subject</a>
29+
</center>
30+
<h1>Add Subjects</h1>
31+
<form action="" method="post" enctype="multipart/form-data">
32+
<label>Name: </label><input type="text" name="name"/><br/>
33+
<label>Marks: </label><input type="number" name="marks" /><br/>
34+
<label>Image: </label><input type="file" name="image"/><br/>
35+
<input type="submit" name="submit" />
36+
</form>
Loading

2/config.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$dbhost = "localhost";
4+
$dbuser = "root";
5+
$dbpass = "root";
6+
$dbname = "test_db";
7+
8+
//Connect to MySQL Server
9+
$con = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);
10+
11+
12+
include "functions.php";
13+

0 commit comments

Comments
 (0)