从HTML表单发布到DB获取UNDEFINED INDEX错误

时间:2014-03-18 13:15:18

标签: php html mysql

我有这个HTML表单,它使用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>

当完成字段并运行它时,我会得到每个条目。

注意:未定义的索引:第9行的C:\ xampp \ htdocs \ toolbox \ wwinsert.php中的StoreNumber

有人能指出我正确的方向来解决这个错误吗?

抱歉忘了我的wwinsert.php代码

<?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 个答案:

答案 0 :(得分:0)

您是否在发布的数据周围有引号取决于您的数据库期望的数据类型(是字符串还是数字?)。

'$_POST["StoreNumber"]'将您的StoreNumber作为一个文本字符串发送到数据库,如果您的数据库字段需要某种整数,则可能会也可能不接受它。有时,数据库引擎会自动将字符串编号解释为整数,但您有机会让DB接受数据或以正确的格式存储数据。

你应该按照我在上面发布的方式引用你的真实字符串(text,varchar等),并使你的整数没有外部引号,如$_POST["StoreNumber"]