-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_insert_item.php
More file actions
42 lines (37 loc) · 1.61 KB
/
php_insert_item.php
File metadata and controls
42 lines (37 loc) · 1.61 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
<html>
<body>
<h3>Enter information about an item to add to the database:</h3>
<form action="php_insert_item.php" method="post">
Name: <input type="text" name="name"><br>
Price_Per_LB: <input type="text" name="price_per_lb"><br>
Roasting: <input type="text" name="roasting"><br>
<input name="submit" type="submit" >
</form>
<br><br>
<?php
include("php_db.php"); // include database class
// replace ' ' with '\ ' in the strings so they are treated as single command line a
$name = $_POST[name];
$price_per_lb = $_POST[price_per_lb];
$roasting = $_POST[roasting];
echo $price_per_lb;
if (isset($_POST['submit']))
{
$myDb = new php_db('MYUSERNAME','MYSQLPASSWORD','MYUSERNAME'); // create a new object, class php_db(), replace MYUSERNAME and MYSQLPASSWORD with your MySQL username and password
//initialize database
$myDb->initDatabase();
// show Items data before inserting a record
$Items = $myDb->query('SELECT * FROM ITEM'); // we show data befor and after the insert
echo '<br>Table ITEM before:';
$myDb->printTable($Items);
$id='90'; // change ID everytime you run your program
$values = '\''. $id. '\', \'' . $name . '\', \'' . $price_per_lb . '\', \''. $roasting . '\' ';
$myDb->insert('ITEM', $values);
// show Item data after inserting a record
$Items = $myDb->query('SELECT * from ITEM'); // select ALL from Restaurant - After the insert
echo '<br>Table Item after:';
$myDb->printTable($Items);
}
?>
</body>
</html>