Ok, I figured out what was happening that caused the last error and fixed it. Now, I'm not getting anymore mysql errors. But, when I click submt, no changes are saved. Instead trying to simplify my code for the sake of this post, I'm going plop the whole thing so you all can see it.
Now my actual code looks like this:
Code: Select all
<?
if(isset($_GET['fid'])){
$fid=$_GET['fid'];
//connect to the database
$sql="SELECT * FROM FoodLib WHERE foodid=" . $fid;
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$foodname =$row['foodname'];
$foodsubname =$row['foodsubname'];
$brand = $row['brand'];
$description = $row['description'];
$foodtype = $row['foodtype'];
$upccode = $row['upccode'];
$servingsize = $row['servingsize'];
$servingunits = $row['servingunits'];
$servingsize2 = $row['servingsize2'];
$servingunits2 = $row['servingunits2'];
$servingsize3 = $row['servingsize3'];
$servingunits3 = $row['servingunits3'];
$calories = $row['calories'];
$calfromfat = $row['calfromfat'];
$totalfat = $row['totalfat'];
$satfat = $row['satfat'];
$transfat = $row['transfat'];
$polyunsatfat = $row['polyunsatfat'];
$monounsatfat = $row['monounsatfat'];
$cholesterol = $row['cholesterol'];
$sodium = $row['sodium'];
$potassium = $row['potassium'];
$totalcarb = $row['totalcarb'];
$dietaryfiber = $row['dietaryfiber'];
$sugar = $row['sugar'];
$protein = $row['protein'];
$vita = $row['vita'];
$vitc = $row['vitc'];
$calcium = $row['calcium'];
$iron = $row['iron'];
$vitd = $row['vitd'];
$vite = $row['vite'];
$vitk = $row['vitk'];
$thiamin = $row['thiamin'];
$riboflavin = $row['riboflavin'];
$niacin = $row['niacin'];
$vitb6 = $row['vitb6'];
$folicacid = $row['folicacid'];
$vitb12 = $row['vitb12'];
$biotin = $row['biotin'];
$pantothenicacid = $row['pantothenicacid'];
$phosphorus = $row['phosphorus'];
$iodine = $row['iodine'];
$magnesium = $row['magnesium'];
$zinc = $row['zinc'];
$selenium = $row['selenium'];
$copper = $row['copper'];
$manganese = $row['manganese'];
$chromium = $row['chromium'];
$molybdenum = $row['molybdenum'];
$optionname = $row['optionname'];
}
}
?>
<?
if(isset($_POST['subjoin'])){
if(!$_POST['servingsize']){
$reqerrors[] = "Yes";
$servingsizeerror = "\t<br><span class=pred>You must enter amount of servings.</span>\n";
}
elseif(is_numeric($_POST['servingsize']) && $_POST['servingsize'] > 0) {
}
else {
$reqverrors[] = "Yes";
$servingsizeerror = "\t<br><span class=pred>Invalid value entered.</span>\n";
}
/* Make sure field is populated */
if(!$_POST['servingunits']){
$reqerrors[] = "Yes";
$servingunitblankerror = "\t<br><span class=pred>You must enter a serving units.</span>\n";
}
/* Once populated, make sure field is populated with letters and spaces only*/
elseif(!preg_match("/^([a-zA-Z])+$/", $_POST['servingunits'])) {
/* elseif(!preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["servingunits"])) { */
$reqverrors[] = "Yes";
$errName = "\t<br><span class=pred>Units must be from letters and spaces.</span>\n";
}
function updateFood()
{
/* Add the new account to the database */
$foodname = mysql_real_escape_string($_POST['foodname']);
$foodsubname = mysql_real_escape_string($_POST['foodsubname']);
$brand = mysql_real_escape_string($_POST['brand']);
$description = mysql_real_escape_string($_POST['description']);
$foodtype = $_POST['foodtype'];
$upccode = $_POST['upccode'];
$servingsize = trim($_POST['servingsize']);
$servingunits = trim($_POST['servingunits']);
$servingsize2 = $_POST['servingsize2'];
$servingunits2 = $_POST['servingunits2'];
$servingsize3 = $_POST['servingsize3'];
$servingunits3 = $_POST['servingunits3'];
$calories = trim($_POST['calories']);
$calfromfat = $_POST['calfromfat'];
$totalfat = $_POST['totalfat'];
$satfat = $_POST['satfat'];
$transfat = $_POST['transfat'];
$polyunsatfat = $_POST['polyunsatfat'];
$monounsatfat = $_POST['monounsatfat'];
$cholesterol = $_POST['cholesterol'];
$sodium = $_POST['sodium'];
$potassium = $_POST['potassium'];
$totalcarb = $_POST['totalcarb'];
$dietaryfiber = $_POST['dietaryfiber'];
$sugar = $_POST['sugar'];
$protein = $_POST['protein'];
$vita = $_POST['vita'];
$vitc = $_POST['vitc'];
$calcium = $_POST['calcium'];
$iron = $_POST['iron'];
$vitd = $_POST['vitd'];
$vite = $_POST['vite'];
$vitk = $_POST['vitk'];
$thiamin = $_POST['thiamin'];
$riboflavin = $_POST['riboflavin'];
$niacin = $_POST['niacin'];
$vitb6 = $_POST['vitb6'];
$folicacid = $_POST['folicacid'];
$vitb12 = $_POST['vitb12'];
$biotin = $_POST['biotin'];
$pantothenicacid = $_POST['pantothenicacid'];
$phosphorus = $_POST['phosphorus'];
$iodine = $_POST['iodine'];
$magnesium = $_POST['magnesium'];
$zinc = $_POST['zinc'];
$selenium = $_POST['selenium'];
$copper = $_POST['copper'];
$manganese = $_POST['manganese'];
$chromium = $_POST['chromium'];
$molybdenum = $_POST['molybdenum'];
$q = "UPDATE FoodLib SET foodname = '$foodname', foodsubname = '$foodsubname', brand = '$brand', description = '$description', foodtype = '$foodtype', upccode = '$upccode', servingsize = '$servingsize', servingunits = '$servingunits', servingsize = '$servingsize', servingunits = '$servingunits', servingsize = '$servingsize', servingunits = '$servingunits', calories = '$calories', calfromfat = '$calfromfat', totalfat = '$totalfat', satfat = '$satfat', transfat = '$transfat', polyunsatfat = '$polyunsatfat', monounsatfat = '$monounsatfat', cholesterol = '$cholesterol', sodium = '$sodium', potassium = '$potassium'
, totalcarb = '$totalcarb', dietaryfiber = '$dietaryfiber', sugar = '$sugar', protein = '$protein', vita = '$vita', vitc = '$vitc', calcium = '$calcium', iron = '$iron', vitd = '$vit', vite = '$vite', vitk = '$vitk', thiamin = '$thiamin', riboflavin = '$riboflavin', niacin = '$niacin', vitb6 = '$vitb6', folicacid = '$folicacid', vitb12 = '$vitb12', biotin = '$biotin', pantothenicacid = '$pantothenicacid', phosphorus = '$phosphorus', iodine = '$iodine', magnesium = '$magnesium', zinc = '$zinc', selenium = '$selenium', copper = '$copper', manganese = '$manganese', chromium = '$chromium'
, molybdenum = '$molybdenum' WHERE foodid = '$fid'";
$ureturn = mysql_query($q) or die(mysql_error());
}
if(empty($reqerrors) && empty($errors) && empty($reqverrors)){
updateFood();
}
else {
$anyerror = "\t<div class=pred>FOOD UPDATE NOT YET SUBMITTED!</div>\n";
}
if(empty($reqerrors)) {
}
else {
$reqberror = "\t<div class=pred><b>ERROR: </b>You didn't fill in a required field. See below.</div>\n";
}
if(empty($reqverrors)) {
}
else {
$reqverror = "\t<div class=pred><b>ERROR: </b>You entered an invalid value in a required field. See below.</div>\n";
}
if(empty($errors)) {
}
else {
$optverror = "\t<div class=pred><b>ERROR: </b>You entered an invalid value in an optional field. See below.</div>\n";
}
}
?>