-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_insert_model_code.php
More file actions
56 lines (51 loc) · 1.65 KB
/
admin_insert_model_code.php
File metadata and controls
56 lines (51 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
session_start();
$model_id = $_POST['id'];
$Did = $_POST['did'];
$ar_name = $_POST['artist_name'];
$year = $_POST['year'];
$title = $_POST['title'];
$size = $_POST['size'];
$type = $_POST['type'];
//code for value check
if(!empty($model_id) && !empty($Did) && !empty($ar_name) && !empty($year) && !empty($title) && !empty($size) && !empty($type))
{
// create connection
$conn = new mysqli("localhost", "root", "", "museumsys");
if(mysqli_connect_error()){
die('Connect Error(' . mysqli_connect_errno().')'.mysqli_connect_error());
}
else
{
$SELECT = "SELECT id From model Where id = ? Limit 1";
$INSERT = "INSERT INTO model(id, Did, size, type, title, artist_name, year) VALUES (?,?,?,?,?,?,?)";
//Prepare statement
//checking if same id item exists or not
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $model_id);
$stmt->execute();
$stmt->bind_result($model_id);
$stmt->store_result();
$rnum = $stmt->num_rows;
$stmt->close();
if($rnum==0){
//id does not exist so we can insert it safely
$dtmt = $conn->prepare($INSERT);
$dtmt->bind_param("sssssss", $model_id, $Did, $size, $type, $title, $ar_name, $year);
$dtmt->execute();
$dtmt->close();
$_SESSION['msg'] = "<script>window.alert('New model inserted successfully')</script>";
header("location: admin_check_logistics.php");
}else{
$_SESSION['msg'] = "<script>window.alert('Item already present with same model id.')</script>";
header("location: admin_check_logistics.php");
}
$conn->close();
}
}
else{
$_SESSION['msg'] = "<script>window.alert('All fields are required')</script>";
die();
header("location: admin_check_logistics.php");
}
?>