I am working on a web interface for my wife and I to keep track of our food supplies. I have created a database and am almost done with the interface. I've run into a problem of one of the values from my list box not being passed. See my code below:
inventory_frontend:
<?php
/This module presents the form for the user to select 'in-stock' items. Each time an 'in stock' item is acquired, it should be entered here, and each time an 'in-stock' item is used/discarded, it should be updated here. The 'Add' portion of this page should list every item in the master table and allow input of quantity (how many of said item should be entered), while the delete portion of the page should do similar. Fields of interest include amount acquired and expiration date of said item./
//First, we determine necessity and if true, include database functions:
// if ($database_connect != true) //If it's false, it hasn't been loaded yet.
include("database_connect.php");
//Next we start the HTML
?>
<html>
<head>
<title>Add/Delete Inventory in Supplies Database</title>
</head>
<body>
<center><h1>Add "In stock" items</h1></center>
<table align=center width=300 height=300>
<tr align=center>
<form method="post" action="test.php">
<td align=center>
Existing:<br>
<select name="item">
<?php
//Here we need to add code to load the records from the Master table into <option> tags
loadMaster();
?>
</select>
</td>
</tr>
<tr>
<td align=center>
How many?<br><input type="text" size="2">
</td>
<td align=center>
Expiration date:<br>
<select name="Month">
<option>January
<option>February
<option>March
<option>April
<option>May
<option>June
<option>July
<option>August
<option>September
<option>October
<option>November
<option>December
</select>
<input type="text" name="Date" size=2><input type="text" name="Year" size=4>
</td>
</tr>
<tr>
<td align=center>
<input type="submit" value="Add to database">
<input type='hidden' name='form' value='add'>
</td>
</form>
</tr>
</table><br><br><br>
<center><h1>Delete "In Stock" items from database</h1></center>
<form method="post" action="inventory-backend.php">
<select name="delete">
<?php loadInventory(); ?>
</select>
<input type='submit' value="Delete item">
<input type='hidden' name='form' value='delete'>
</form>
</body>
</html>
<?php
//And finally, we close the link to the mysql object
mysql_close($link);
?>
test.php:
<?php
include("database_connect.php");
$typeofform = $POST['form'];
switch($typeofform)
{
case "add":
$item = $POST['item'];
$name = findName($item);
$month = $POST['Month'];
$date = $POST['Date'];
$year = $_POST['Year'];
//We'll need to convert month, date and year into something our database understands...
switch ($month)
{
case "January"; $intMonth = 1; break;
case "February"; $intMonth = 2; break;
case "March"; $intMonth = 3; break;
case "April"; $intMonth = 4; break;
case "May"; $intMonth = 5; break;
case "June"; $intMonth = 6; break;
case "July"; $intMonth = 7; break;
case "August"; $intMonth = 8; break;
case "September"; $intMonth = 9; break;
case "October"; $intMonth = 10; break;
case "November"; $intMonth = 11; break;
case "December"; $intMonth = 12; break;
}
$expDate = mktime(0, 0, 0, $intMonth, $year);
print "expDate = $expDate<br><br>\n";
$query = "SELECT ID FROM Master WHERE Name = '$item';";
/print "Break 1\n\n";
print "$query<br><br>\n";/
$result = mysql_query($query);
if (!$result) die("Could not retrieve CategoryID: ".mysql_error());
$a_row = mysql_fetch_array($result);
$masterID = $a_row['ID'];
//We have our MasterID so we can construct our query
$query = "INSERT INTO Inventory (MasterID, ExpirationDate) VALUES ('$masterID', '$expDate');";
print "$query<br><br>\n";
if (!mysql_query($query, $link))
die("Could not add record to database: ".mysql_error());
else
//Do something else
break;
}
mysql_close($link);
?>
Here is the output of test.php:
Warning: mktime() [function.mktime]: It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in /home/michael/public_html/supplies/test.php on line 32
expDate = 1496466000
INSERT INTO Inventory (MasterID, ExpirationDate) VALUES ('', '1496466000');
Can anyone tell me why item is not being passed to test.php?