-1

I am doing a MySQL update statement and when I click submit, the update happens, but the word "undefined" is returned and that's the only thing returned, printed in the upper left corner of the page.

I've double checked that all my variables are defined, so I have no idea to what this could be referring to.

Below is my code for the update query.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Add Beer for Brew Log</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<style type="text/css">
.standardfont {
    font-family: Tahoma, Geneva, sans-serif;
    font-size: 12px;
}
</style>
</head>
<?
include "dblogin.php";//database connection

$ID = $_POST['ID'];
$Beer = $_POST['Beer'];
$BrewDate = $_POST['BrewDate'];
$EndOfPrimary = $_POST['EndOfPrimary'];
$EndOfSecondary = $_POST['EndOfSecondary'];
$PackagingDate = $_POST['PackagingDate'];
$AnticipatedOG = $_POST['AnticipatedOG'];
$MashDuration = $_POST['MashDuration'];
$MashRatio = $_POST['MashRatio'];
$MashTempTarget = $_POST['MashTempTarget'];
$StrikeWaterTemp = $_POST['StrikeWaterTemp'];
$StrikeWaterVolume = $_POST['StrikeWaterVolume'];
$MashTempActualStart = $_POST['MashTempActualStart'];
$MashTempActualEnd = $_POST['MashTempActualEnd'];
$FirstRunningsVolume = $_POST['FirstRunningsVolume'];
$FirstRunningsGravity = $_POST['FirstRunningsGravity'];
$SpargeType = $_POST['SpargeType'];
$Infusion2Volume = $_POST['Infusion2Volume'];
$Infusion2Temp = $_POST['Infusion2Temp'];
$Infusion2MashTemp = $_POST['Infusion2MashTemp'];
$Infusion2RunningsVolume = $_POST['Infusion2RunningsVolume'];
$Infusion2RunningsGravity = $_POST['Infusion2RunningsGravity'];
$Infusion3Volume = $_POST['Infusion3Volume'];
$Infusion3Temp = $_POST['Infusion3Temp'];
$Infusion3MashTemp = $_POST['Infusion3MashTemp'];
$Infusion3RunningsVolume = $_POST['Infusion3RunningsVolume'];
$Infusion3RunningsGravity = $_POST['Infusion3RunningsGravity'];
$SG = $_POST['SG'];
$MashEfficiency = $_POST['MashEfficiency'];
$BoilDuration = $_POST['BoilDuration'];
$Finings = $_POST['Finings'];
$OG = $_POST['OG'];
$VolumePreboil = $_POST['VolumePreboil'];
$VolumePostBoil = $_POST['VolumePostBoil'];
$VolumeInFermenter = $_POST['VolumeInFermenter'];
$FermCheck1Date = $_POST['FermCheck1Date'];
$FermCheck1Temp = $_POST['FermCheck1Temp'];
$FermCheck1Gravity = $_POST['FermCheck1Gravity'];
$FermCheck2Date = $_POST['FermCheck2Date'];
$FermCheck2Temp = $_POST['FermCheck2Temp'];
$FermCheck2Gravity = $_POST['FermCheck2Gravity'];
$FermCheck3Date = $_POST['FermCheck3Date'];
$FermCheck3Temp = $_POST['FermCheck3Temp'];
$FermCheck3Gravity = $_POST['FermCheck3Gravity'];
$FG = $_POST['FG'];
$PackagingType = $_POST['PackagingType'];
$CarbonationType = $_POST['CarbonationType'];
$CarbonationVolume = $_POST['CarbonationVolume'];
$Notes = $_POST['Notes'];

$query = "UPDATE brewlog 
          SET   EndOfPrimary='$EndOfPrimary',
                EndOfSecondary='$EndOfSecondary',
                PackagingDate='$PackagingDate',
                AnticipatedOG='$AnticipatedOG',
                MashDuration='$MashDuration',
                MashRatio='$MashRatio',
                MashTempTarget='$MashTempTarget',
                StrikeWaterTemp='$StrikeWaterTemp',
                StrikeWaterVolume='$StrikeWaterVolume',
                MashTempActualStart='$MashTempActualStart',
                MashTempActualEnd='$MashTempActualEnd',
                FirstRunningsVolume='$FirstRunningsVolume',
                FirstRunningsGravity='$FirstRunningsGravity',
                SpargeType='$SpargeType',
                Infusion2Volume='$Infusion2Volume',
                Infusion2Temp='$Infusion2Temp',
                Infusion2MashTemp='$Infusion2MashTemp',
                Infusion2RunningsVolume='$Infusion2RunningsVolume',
                Infusion2RunningsGravity='$Infusion2RunningsGravity',
                Infusion3Volume='$Infusion3Volume',
                Infusion3Temp='$Infusion3Temp',
                Infusion3MashTemp='$Infusion3MashTemp',
                Infusion3RunningsVolume='$Infusion3RunningsVolume',
                Infusion3RunningsGravity='$Infusion3RunningsGravity',
                SG='$SG',
                MashEfficiency='$MashEfficiency',
                BoilDuration='$BoilDuration',
                Finings='$Finings',
                OG='$OG',
                VolumePreboil='$VolumePreboil',
                VolumePostBoil='$VolumePostBoil',
                VolumeInFermenter='$VolumeInFermenter',
                FermCheck1Date='$FermCheck1Date',
                FermCheck1Temp='$FermCheck1Temp',
                FermCheck1Gravity='$FermCheck1Gravity',
                FermCheck2Date='$FermCheck2Date',
                FermCheck2Temp='$FermCheck2Temp',
                FermCheck2Gravity='$FermCheck2Gravity',
                FermCheck3Date='$FermCheck3Date',
                FermCheck3Temp='$FermCheck3Temp',
                FermCheck3Gravity='$FermCheck3Gravity',
                FG='$FG',
                PackagingType='$PackagingType',
                CarbonationType='$CarbonationType',
                CarbonationVolume='$CarbonationVolume',
                Notes='$Notes'            
          WHERE ID='$ID'";
$result = mysql_query($query) or die(mysql_error());
?>
Done.
TheAleMaster
  • 83
  • 2
  • 9
  • 3
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use [a modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to** [**SQL injection attacks**](http://bobby-tables.com/) that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – DCoder May 11 '13 at 16:51
  • roll up your sleeves and get them into PDO – Drew May 11 '13 at 16:53
  • Doing database operations in php code is not a very good choice; build some middleware and have your page interact with that instead. – raffian May 11 '13 at 17:03
  • What you're doing here is reckless and will get you burned because you're obviously oblivious to [proper SQL escaping](http://bobby-tables.com/php) and [SQL injection bugs](http://bobby-tables.com/). You should learn more about those before you write another line of MySQL interfacing code. You cannot write code like this and expect it to work properly. – tadman May 11 '13 at 17:42

1 Answers1

1

You are obviously trying to use MySQL without knowledge how to do it safely (or at all at that :) ).

I would recommend learning MySQL or using some ORM - you will find they help you focus on coding the logic not tedious querywriting ...

Best ORM i know is RedBeanPHP - its small, fast and easy to use.

Its also flexible - you dont have to design the database layout before developing, need to add a field to a table ? no problem just $object->newfield="hi!";

And it is database agnostic ( :D ) - should your client choose to switch to PostgreSQL or so, you can do migration with one line of code.

http://redbeanphp.com/ give it a try.

n00b
  • 5,642
  • 2
  • 30
  • 48