-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertData_save.php
More file actions
47 lines (43 loc) · 1.46 KB
/
insertData_save.php
File metadata and controls
47 lines (43 loc) · 1.46 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
<?php
session_start();
if (isset($_SESSION["session_flag"])) {
if($_SESSION["session_flag"] == "valid") {
$host = "HOST WEBSITE";
$user = "MY USERNAME";
$pass = "*******";
$db = "DATABASE NAME";
$conn = mysql_connect("$host", "$user", "$pass");
$dblink = mysql_select_db("DATABASE");
// Check connection
if(!$dblink){
die("ERROR: Could not connect. " . mysql_error());
}
if (isset($_POST)) {
// Escape user inputs for security
$ObjectName = $_POST['objectname'];
$Quantity = $_POST['quantity'];
$Quality = $_POST['quality'];
$Resulting = $_POST['resulting'];
echo 'You have ' .$Quantity. ' of ' .$Quality. ' quality ' .$ObjectName.'<br>';
echo 'You can combine it to create ' .$Resulting. '<br><br>';
}
// attempt insert query execution
$sql = "INSERT INTO Object (ObjectName, Quantity, Quality, ResultingObjectName) VALUES ('$ObjectName', '$Quantity', '$Quality', '$Resulting')";
$query = mysql_query($sql);
if(! $query ) {
die('ERROR: ' . mysql_error());
} else {
echo "Record added successfully. <br />";
}
// close connection
mysql_close();
echo "<a href=\"viewAll.php\"> Click here </a> to view list of all objects. <br>";
echo "<a href=\"main.html\"> Click here </a> to go to main menu.";
} else {
echo "Invalid session!";
}
} else {
echo "Session not set!";
echo "<a href=\"login.html\">Click here </a> to go back to the main page.";
}
?>