-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchargeinsert.php
73 lines (48 loc) · 2.24 KB
/
chargeinsert.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
$errorp = ""; // Variable To Store Error Message
if (isset($_POST['submit'])) {
$date =$_POST['chargedate'];
$voltbefore =$_POST['voltbefore'];
$voltafter =$_POST['voltafter'];
$chargetime =$_POST['chargetime'];
$chargecurrent =$_POST['chargecurrent'];
$chargereceived=$_POST['chargereceived'];
$chargedby =$_POST['chargedby'];
$flight=$_POST['flight'];
if (!preg_match("/^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/",$chargetime)) {
$errorp = "invalid time format";
}
elseif (empty($_POST['chargedate']) || empty($_POST['voltbefore'])
|| empty($_POST['voltafter'])
|| empty($_POST['chargetime'])
|| empty($_POST['chargecurrent'])
|| empty($_POST['chargereceived'])
|| empty($_POST['chargedby'])
|| empty($_POST['selectbatt']))
{
$errorp = "Complete all required fields";
echo $errorp;
}
else
{
$field1 = mysqli_real_escape_string($conn,$_POST['selectbatt']);
$field2 = mysqli_real_escape_string($conn,$_POST['chargedate']);
$field3 = mysqli_real_escape_string($conn,$_POST['voltbefore']);
$field4 = mysqli_real_escape_string($conn,$_POST['voltafter']);
$field5 = mysqli_real_escape_string($conn,$_POST['chargetime']);
$field6 = mysqli_real_escape_string($conn,$_POST['chargecurrent']);
$field7 = mysqli_real_escape_string($conn,$_POST['chargereceived']);
$field8 = mysqli_real_escape_string($conn,$_POST['chargedby']);
$field9 = mysqli_real_escape_string($conn,$flight);
$query = "INSERT INTO charge (batteries_id, date_charge, bvolt_before, bvolt_after, chargin_duration, chargin_current,charge_received,crew_id, flight_id)
VALUES ('{$field1}','{$field2}','{$field3}','{$field4}','{$field5}','{$field6}','{$field7}','{$field8}' ,'{$field9}')";
$sent= mysqli_query($conn,$query);
if (!$sent) {
die('Error: ' . mysqli_error($conn));
}
else
{
$errorp="record added";
}
}}
?>