-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadditem.php
44 lines (43 loc) · 914 Bytes
/
additem.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
<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
if($_SESSION["valid"] != 1){
header("Location: index.php");
}
if($_SERVER["REQUEST_METHOD"] == "POST"){
if($_POST["name"] == ""){
echo "Please input name";
}
else{
$dbname="db123";$servername = "sn123"; $username = "un123"; $password = "pw123";
$con = mysqli_connect($servername, $username, $password, $dbname);
if(!$con){
die("MYSQL Connection Failed:" . $con->connect_error);
}
$name = $_POST["name"];
$sql = "INSERT INTO items(name) VALUES('$name');";
if($con->query($sql) === TRUE){
echo $name . " Added successfully!";
}
else{
echo "error" . $con->error;
}
}
}
?>
<center><h1> Add Item </h1>
<form method="post">
<input type="text" name="name"><br>
<input type="submit" value="Add Item">
</form>
<br>
<a href="home.php"><button>Go Home</button></a>
</center>
</body>
</html>