-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlinsert.php
53 lines (39 loc) · 1.46 KB
/
sqlinsert.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
<?php
$servername = "localhost";
$username = "ageCalc";
$password = "password";
$dbname = "ageCalcRecords";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$Fname = mysqli_real_escape_string($conn, $_POST['Fname']);
$Sname = mysqli_real_escape_string($conn, $_POST['Sname']);
$birthday = mysqli_real_escape_string($conn, $_POST['birthday']);
$ageRecorded = mysqli_real_escape_string($conn, $_POST['ageRecorded']);
$MarsageRecorded = mysqli_real_escape_string($conn, $_POST['MarsageRecorded']);
$timestamp = mysqli_real_escape_string($conn, $_POST['timestamp']);
//echo $name;
//echo "<br>";
//echo $timestamp;
//echo "<br>";
//echo $birthday;
//echo "<br>";
//echo $ageRecorded;
//echo "<br>";
//convert to sql date formate
$timestampSQL= new DateTime("@$timestamp");
$timestampSQL->setTimezone(new DateTimeZone('Australia/Sydney'));
$birthdaySQL= new DateTime("@$birthday");
$birthdaySQL->setTimezone(new DateTimeZone('Australia/Sydney'));
$timestampStr=$timestampSQL->format('Y-m-d H:i:s');
$birthdayStr=$birthdaySQL->format('Y-m-d H:i:s');
//echo timestampStr;
//echo "<br>";
//echo $birthdayStr;
//echo "<br>";
$insertState = "INSERT INTO record_of_request2 (FName, SName, BirthDate, EntryDate, AgeRecorded, MarsAgeRecorded) Values('$Fname','$Sname','$birthdayStr','$timestampStr','$ageRecorded','$MarsageRecorded')";
$conn->query($insertState);
$conn->close();
echo "done";
?>