-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuy_products.php
87 lines (69 loc) · 2.57 KB
/
buy_products.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" media="screen">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script src="js/colpick.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/colpick.css" type="text/css"/>
<script src = "js/usersChoice.js"></script>
</head>
<body background="images/background.jpg">
<?php include('interface.php'); ?>
<div>
<table border = "1" bgcolor = "#85C285">
<tr>
<form action="buy_products.php" method="post">
<td>
<table>
<tr>
<td><label for="nameID" > Name: </label></td>
<td><input type="text" name="name" id="nameID"></td>
</tr>
<tr>
<td> <label for = "emailID"> Email: </label></td>
<td> <input type = "text" id = "emailID" name = "email"></td>
</tr>
<tr>
<td> <label for = "product_nameID"> Name of product: </label></td>
<td> <input type = "text" id = "product_nameID" name = "product_name"></td>
</tr>
<tr>
<td></td>
<td> <input type = "submit" name = "order" value = "Order now"> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
$host="mysql.metropolia.fi"; // Host name
$username="anp"; // Mysql username
$password="anphu123"; // Mysql password
$db_name="anp"; // Database name
$tbl_name="Ordered_products"; // Table name
// Connect to server and select databse.
$connect = mysqli_connect("$host", "$username", "$password");
if(mysqli_connect_errno($connect)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_select_db($connect, "$db_name")or die("cannot select DB");
if (isset($_POST['order'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$product = $_POST['product_name'];
$sql = "INSERT INTO Ordered_products (Name, Email, Product_name) VALUES (?, ?, ?)";
$stmt = mysqli_prepare($connect, $sql);
mysqli_stmt_bind_param($stmt, "sss", $val1, $val2, $val3);
$val1 = $name;
$val2 = $email;
$val3 = $product;
//$val4 = $myusername;
$temp = mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
?>
</div>
</body>
</html>