0

I have this HTML form it is formatted using CSS.

<form action="wwinsert.php" method="post">
<fieldset>
<legend>Weekly Work</legend>
<p><label class="lab1" for="StoreNumber">Store:</label><input type="text" name="StoreNumber" class="textbox-300"></p>
<p><label class="lab1" for="WeekEndingDate">Week Ending:</label><input type="date" name="WeekEndingDate" class="textbox-300"></p>
<p><label class="lab1" for="ActualSales">Actual Sales:</label><input type="number" name="ActualSales" class="textbox-300"></p>
<p><label class="lab1" for="SalesonLastYear">Sales% on Last Year:</label><input type="number" name="SalesonLastYear" class="textbox-300"></p>
<p><label class="lab1" for="ProjectedSales">Projected Sales:</label><input type="number" name="ProjectedSales" class="textbox-300"></p>
<p><label class="lab1" for="SalesVsProjections">Sales% Vs Projections:</label><input type="number" name="SalesVsProjections" class="textbox-300"></p>
<p><label class="lab1" for="GuestCount">Guest Count:</label><input type="number" name="GuestCount" class="textbox-300"></p>
<p><label class="lab1" for="GuestCountVsLastYear">Guest Count % Vs Last Year:</label><input type="number" name="GuestCountVsLastYear" class="textbox-300"></p>
<p><label class="lab1" for="ActualLabour">Actual Labour:</label><input type="number" name="ActualLabour" class="textbox-300"></p>
<p><label class="lab1" for="ProjectedLabour">Projected Labour:</label><input type="number" name="ProjectedLabour" class="textbox-300"></p>
<p><label class="lab1" for="BaseFoodCost">Base Food Cost:</label><input type="number" name="BaseFoodCost" class="textbox-300"></p>
<p><label class="lab1" for="ActualFoodCost">Actual Food Cost:</label><input type="number" name="ActualFoodCost" class="textbox-300"></p>
<p><label class="lab1" for="FullWaste">Full Waste %:</label><input type="number" name="FullWaste" class="textbox-300"></p>
<p><label class="lab1" for="RawWaste">Raw Waste %:</label><input type="number" name="RawWaste" class="textbox-300"></p>
<p><label class="lab1" for="EMeals">E-Meals %:</label><input type="number" name="EMeals" class="textbox-300"></p>
<p><label class="lab1" for="Promo">Promo %:</label><input type="number" name="Promo" class="textbox-300"></p>
<p><label class="lab1" for="NonRecipe">Non Recipe %:</label><input type="number" name="NonRecipe" class="textbox-300"></p>
<p><label class="lab1" for="Deviation">Deviation %:</label><input type="number" name="Deviation" class="textbox-300"></p>
<p><label class="lab1" for="FryYield">Fry Yield:</label><input type="number" name="FryYeild" class="textbox-300"></p>
<p><label class="lab1" for="LettuceYield">Lettuce Yield:</label><input type="number" name="LettuceYeild" class="textbox-300"></p>
<p><label class="lab1" for="SundaeYield">Sundae Yield:</label><input type="number" name="SundaeYeild" class="textbox-300"></p>
<p><label class="lab1" for="ShakeYield">Shake Yield:</label><input type="number" name="ShakeYeild" class="textbox-300"></p>
<p><label class="lab1" for="Cash">Cash +/-:</label><input type="number" name="Cash+/-" class="textbox-300"></p>
<p><label class="lab1" for="NumberofTotalRefunds">Number of Total Refunds:</label><input type="number" name="NumberOfTotalRefunds" class="textbox-300"></p>
<p><label class="lab1" for="RefundsTotal">Refunds Total:</label><input type="number" name="RefundsTotal" class="textbox-300"></p>
<p><label class="lab1" for="TREDSBeforeTotal">T/REDS Before Total:</label><input type="number" name="T/RedsBeforeTotal" class="textbox-300"></p>
<p><label class="lab1" for="TREDSBeforeTotalValue">T/REDS Before Total Pounds:</label><input type="number" name="TRedsBeforeTotalValue" class="textbox-300"></p>
<p><label class="lab1" for="WeeklykWusage">Weekly kW usage:</label><input type="number" name="WeeklykWUsage" class="textbox-300"></p>
<p><label class="lab1" for="EnergyCost">Energy Cost:</label><input type="number" name="EnergyCost" class="textbox-300"></p>
<p><label class="lab1" for="TrainingAuditDate">Training Audit Date:</label><input type="Date" name="TrainingAuditDate" class="textbox-300"></p>
<p><label class="lab1" for="TrainingAuditScore">Training Audit Score:</label><input type="number" name="TrainingAuditScore" class="textbox-300"></p>
<p><label class="lab2" for="PLProjectedSales">P&L Projected Sales:</label><input type="number" name="P&LProjectedSales" class="textbox-300"></p>
<p><label class="lab2" for="PLProjectedLabour">P&L Projected Labour:</label><input type="number" name="P&LProjectedLabour" class="textbox-300"></p>
<p><label class="lab2" for="PLProjectedFoodCost">P&L Projected Food Cost:</label><input type="number" name="P&LProjectedFoodCost" class="textbox-300"></p>
<p><label class="lab3" for="MonthlyActualSales">Monthly Actual Sales:</label><input type="number" name="MonthlyActualSales" class="textbox-300"></p>
<p><label class="lab3" for="MonthlySalesonLastYear">Monthly Sales% on Last Year:</label><input type="number" name="MonthlySales%OnLastYear" class="textbox-300"></p>
<p><label class="lab3" for="MonthlyActualLabour">Monthly Actual Labour:</label><input type="number" name="MonthlyActualLabour" class="textbox-300"></p>
<p><label class="lab3" for="MonthlyBaseFoodCost">Monthly Base Food Cost:</label><input type="number" name="MonthlyBaseFoodCost" class="textbox-300"></p>
<p><label class="lab3" for="MonthlyActualFoodCost">Monthly Actual Food Cost:</label><input type="number" name="MonthlyActualFoodCost" class="textbox-300"></p>
<p><label class="lab3" for="MonthlyCash">Monthly Cash +/-:</label><input type="number" name="MonthlyCash+/-" class="textbox-300"></p>
<p><label class="lab3" for="HighestBreakfastHour">Highest Breakfast Hour:</label><input type="number" name="HighestBreakfastHour" class="textbox-300"></p>
<p><label class="lab3" for="HighestHour">Highest Hour:</label><input type="number" name="HighestBreakfastShift" class="textbox-300"></p>
<p><label class="lab3" for="RecordCars">Record Cars:</label><input type="number" name="HighestHour" class="textbox-300"></p> 
<p><label class="lab3" for="DriveThru">Drive Thru %:</label><input type="number" name="DriveThru" class="textbox-300"></p> 
<input type="submit" value="Submit">
</fieldset>
</form>

When complete the fields and run it i get for every entry.

Notice: Undefined index: StoreNumber in C:\xampp\htdocs\toolbox\wwinsert.php on line 9

can anyone point me in the right direction on fixing this error?

Sorry forgot my wwinsert.php code

<?php


$con=mysql_connect("login details here");


$sql="INSERT INTO weeklywork(StoreNumber, WeekEndingDate, ActualSales, Sales%onLastYear, ProjectedSales, Sales%VsProjections, GuestCount, GuestCount%VsLastYear, ActualLabour, ProjectedLabour, BaseFoodCost, ActualFoodCost, FullWaste, RawWaste, EMeals, Promo, NonRecipe, Deviation, FryYeild, LettuceYeild, SundaeYeild, ShakeYeild, Cash+/-, NumberOfTotalRefunds, RefundsTotal, T/RedsBeforeTotal, T/RedsBeforeTotalValue, WeeklykWUsage, EnergyCost, TrainingAuditDate, TrainingAuditScore, PLProjectedSales, PLProjectedLabour, PLProjectedFoodCost, MonthlyActualSales, MonthlySalesOnLastYear, MonthlyActualLabour, MonthlyBaseFoodCost, MonthlyActualFoodCost, MonthlyCash, HighestBreakfastHour, HighestBreakfastShift, HighestHour, RecordCarsThisMonth, DriveThru) 
VALUES
    ('$_POST[StoreNumber]','$_POST[WeekEndingDate]','$_POST[ActualSales]','$_POST[SalesonLastYear]','$_POST[ProjectedSales]','$_POST[SalesVsProjections]','$_POST[GuestCount]','$_POST[GuestCountVsLastYear]','$_POST[ActualLabour]','$_POST[ProjectedLabour]','$_POST[BaseFoodCost]','$_POST[ActualFoodCost]','$_POST[FullWaste]','$_POST[RawWaste]','$_POST[EMeals]','$_POST[Promo]','$_POST[NonRecipe]','$_POST[Deviation]','$_POST[FryYeild]','$_POST[LettuceYeild]','$_POST[SundaeYeild]','$_POST[ShakeYeild]','$POST[Cash]','$_POST[NumberOfTotalRefunds]','$_POST[RefundsTotal]','$_POST[TRedsBeforeTotal]','$_POST[TRedsBeforeTotalValue]','$_POST[WeeklykWUsage]','$_POST[EnergyCost]','$_POST[TrainingAuditDate]','$_POST[TrainingAuditScore]','$_POST[PLProjectedSales]','$_POST[PLProjectedLabour]','$_POST[PLProjectedFoodCost]','$_POST[MonthlyActualSales]','$_POST[MonthlySalesOnLastYear]','$_POST[MonthlyActualLabour]','$_POST[MonthlyBaseFoodCost]','$_POST[MonthlyActualFoodCost]','$_POST[MonthlyCash]','$_POST[HighestBreakfastHour]','$_POST[HighestBreakfastShift]','$_POST[HighestHour]','$_POST[RecordCarsThisMonth]','$_POST[DriveThru]')";

    if (mysql_query($con,$sql))
  {
  die('Error: ' . mysql_error($con));
  }
    echo "1 record added";


?>

1 Answers1

0

Whether you have quotes around your posted data or not depends on what your DB is expecting as a datatype (Is it a string or a number?).

This '$_POST["StoreNumber"]' sends your StoreNumber as a string of text to the DB, which may or may not accept it if your DB field requires an integer of some sort. Sometimes the DB engine will automatically interpret the string number as an integer, but you're taking a chance at either having the DB accept the data or storing it in the proper format.

You should have your true strings (text, varchar, etc) quoted the way I posted it above, and have your integers without external quotes like $_POST["StoreNumber"].

gtr1971
  • 2,672
  • 2
  • 18
  • 23
  • My DB is set up as INT, decimal and date should it be $_POST["StoreNumber"]. for these? – user3411540 Mar 18 '14 at 14:14
  • I am now getting this error?Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\toolbox\wwinsert.php on line 9 – user3411540 Mar 18 '14 at 14:20
  • Use single quotes instead of double quotes. The double quotes are interfering with the doubles you used to encapsulate the entire query. – gtr1971 Mar 18 '14 at 14:24
  • '$_POST['StoreNumber']',$_POST['WeekEndingDate'],$_POST['ActualSales'], I have now got this store number is a Varchar, weekending date is a date sales is decimal is this correct? I am still getting the same error? – user3411540 Mar 18 '14 at 14:36
  • Use this pattern: `$query="INSERT INTO...VALUES($_POST['Number'],'$_POST["String"]')";` If you still get an error, try concatenating instead `,'" . $_POST['String'] . "'` – gtr1971 Mar 18 '14 at 14:44
  • It doesn't matter which type of quote you start with (single or double), but they need to match as encapsulators once you start: `" ' " " ' "` or `' " ' ' " '`. – gtr1971 Mar 18 '14 at 14:50
  • tried both getting Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\toolbox\wwinsert.php on line 9 – user3411540 Mar 18 '14 at 15:02
  • The error is telling you exactly what's wrong. There's an unexpected double quote somewhere. Check your work and learn to search the web for errors like this. – gtr1971 Mar 18 '14 at 15:09
  • Should dates be sent as text srtign or numbers? – user3411540 Mar 18 '14 at 15:16