-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.php
34 lines (24 loc) · 1.42 KB
/
Database.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
<?php
require_once("/home/gmn7929/conf/settings.php"); //using require_once to include/add another file, which contains sensitive information about the database in the conf folder
// mysqli_connect returns false if connection failed, otherwise a connection value
$conn = @mysqli_connect($sql_host, $sql_user, $sql_pass, $sql_db); //connecting to the database using the information that has been provided from settings.php file, which I included earlier
// Checks the connection status to see if it it's a successful connection or a failure one.
if (!$conn) {
echo "Database connection failure"; //Display error message to the user
}
$table = "CREATE TABLE IF NOT exists UserRecords (
Existed_Questions VARCHAR(255))";
//using mysqli_query to execute the query to create the table
//using the INSERT INTO command to insert data into the table by the following rows
if (mysqli_query($conn, $table)) {
$insertValues ="INSERT INTO UserRecords(
statuscode, status, share, date, allow)
values('$status_code','$status','$share','$date','$allow')";
//using mysqli_query again to execute the insert command
if(mysqli_query($conn, $insertValues)){
echo "<br>";
echo "<br> Thank you for completing the form";
echo "<br> Your record has been inserted to the database";
}
}
?>