-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
82 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
<?php | ||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
include("../../../Exercise/8/connected_database.php"); | ||
if (!$_SERVER["REQUEST_METHOD"] == "POST") return; | ||
include("../../../Exercise/8/connected_database.php"); | ||
|
||
$fac_id = $_POST['id']; | ||
$fac_name = $_POST['name']; | ||
$faculty_id = $_POST['id']; | ||
$faculty_name = $_POST['name']; | ||
|
||
$sql = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)"; | ||
$stmt = mysqli_prepare($db, $sql); | ||
mysqli_stmt_bind_param($stmt, "is", $fac_id, $fac_name); | ||
$query = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)"; | ||
$stmt = mysqli_prepare($db, $query); | ||
|
||
if (mysqli_stmt_execute($stmt)) { | ||
include("../../functions/previous_page.php"); | ||
} else { | ||
switch (mysqli_errno($db)) { | ||
case '1062': | ||
include("../../functions/previous_page.php"); | ||
break; | ||
mysqli_stmt_bind_param($stmt, "is", $faculty_id, $faculty_name); | ||
|
||
default: | ||
echo "Error: " . $sql . "<br>" . mysqli_error($db); | ||
break; | ||
} | ||
if (mysqli_stmt_execute($stmt)) { | ||
include("../../functions/previous_page.php"); | ||
} else { | ||
switch (mysqli_errno($db)) { | ||
case '1062': | ||
include("../../functions/previous_page.php"); | ||
break; | ||
default: | ||
echo "Error: " . $query . "<br>" . mysqli_error($db); | ||
break; | ||
} | ||
|
||
mysqli_stmt_close($stmt); | ||
mysqli_close($db); | ||
} | ||
|
||
mysqli_stmt_close($stmt); | ||
mysqli_close($db); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
<?php | ||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
include("../../../Exercise/8/connected_database.php"); | ||
if (!$_SERVER["REQUEST_METHOD"] == "POST") return; | ||
include("../../../Exercise/8/connected_database.php"); | ||
|
||
$fac_id = $_POST['Fac_id']; | ||
$sql = "DELETE FROM faculty WHERE Fac_id = ?"; | ||
$faculty_id = $_POST['Fac_id']; | ||
$query = "DELETE FROM faculty WHERE Fac_id = ?"; | ||
|
||
if ($stmt = mysqli_prepare($db, $sql)) { | ||
mysqli_stmt_bind_param($stmt, "i", $fac_id); | ||
if ($stmt = mysqli_prepare($db, $query)) { | ||
mysqli_stmt_bind_param($stmt, "i", $faculty_id); | ||
|
||
if (mysqli_stmt_execute($stmt)) { | ||
header("Location: " . $_SERVER['HTTP_REFERER']); | ||
exit(); | ||
} else { | ||
echo "Error deleting record: " . mysqli_error($db); | ||
} | ||
|
||
mysqli_stmt_close($stmt); | ||
if (mysqli_stmt_execute($stmt)) { | ||
header("Location: " . $_SERVER['HTTP_REFERER']); | ||
exit(); | ||
} else { | ||
echo "Error preparing statement: " . mysqli_error($db); | ||
echo "Error deleting record: " . mysqli_error($db); | ||
} | ||
|
||
mysqli_close($db); | ||
} else { | ||
echo "Error preparing statement: " . mysqli_error($db); | ||
} | ||
|
||
mysqli_stmt_close($stmt); | ||
mysqli_close($db); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
|
||
$query = "SELECT Fac_id, Fac_name FROM faculty"; | ||
$result = mysqli_query($db, $query); | ||
|
||
mysqli_close($db); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
<?php | ||
include("./connected_database.php"); | ||
|
||
if ($_SERVER["REQUEST_METHOD"] == "POST") { | ||
$fac_id = $_POST['id']; | ||
$fac_name = $_POST['name']; | ||
$faculty_id = $_POST['id']; | ||
$faculty_name = $_POST['name']; | ||
|
||
$sql = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)"; | ||
$stmt = mysqli_prepare($db, $sql); | ||
mysqli_stmt_bind_param($stmt, "is", $fac_id, $fac_name); | ||
$query = "INSERT INTO faculty (Fac_id, Fac_name) VALUES (?, ?)"; | ||
$stmt = mysqli_prepare($db, $query); | ||
|
||
if (mysqli_stmt_execute($stmt)) { | ||
echo "New record created successfully"; | ||
} else { | ||
echo "Error: " . $sql . "<br>" . mysqli_error($db); | ||
} | ||
mysqli_stmt_bind_param($stmt, "is", $faculty_id, $faculty_name); | ||
|
||
mysqli_stmt_close($stmt); | ||
mysqli_close($db); | ||
if (mysqli_stmt_execute($stmt)) { | ||
echo "New record created successfully"; | ||
} else { | ||
echo "Error: " . $query . "<br>" . mysqli_error($db); | ||
} | ||
|
||
mysqli_stmt_close($stmt); | ||
mysqli_close($db); |