如果我做错了,请原谅我。我每周5天使用这个网站来帮助我,但这是我第一次真正发布了一个问题。我是自学b / c我被倾倒在维护一个php网站。我知道足够危险,但还不够正确(尚)。所以,当你觉得有必要发表评论时,请善待“WTF是这个小伙吗?!?!?” :)
要点: 我有2个文件:callaway.php& saveaddcallaway.php。 callaway.php连接到mysql db并且检查用户(已经登录的用户)已经在名为tblcallaway的表中有记录。如果他们没有,那么他们有一个表格可供他们提交尺寸,款式和颜色的衬衫订单。在提交时,该表单操作将变量传递给saveaddcallaway.php,然后回显用户的选择。
真的......在提交时,该表单操作将变量传递给saveaddcallaway.php,然后将该订单插入到tblcallaway并将用户重定向回callaway.php并显示“您的订单已提交”消息。但是出于这个问题的目的 - 我们只是假装显示选择是我需要的。
问题: 它有时只能起作用。你可以提交和所有作品都很棒。然后,如果您或其他任何人试图提交,它可能会也可能不会。当它不起作用时,您会收到“Undefined Index”错误...但是如果您单击几次网页刷新按钮,它将显示您的选择!这就像callaway.php只在需要时处理表单选择。当它工作时和它不起作用时,它是非常零星的。我尝试过不同尺寸/颜色/款式的组合。我们重新启动了服务器。它仍然只能工作......有时候。 **只是旁注*:当它设置为插入到tblcallaway时,它会在记录中插入所有空白值。我已经包含了代码,注释掉了,但问题是在它被放入表格之前(我认为)。想想我还是要把它包括在内!
<!--callaway.php-->
<?php
$query = "SELECT * FROM tblCallaway WHERE NetworkID = '$user'" or die("Error in the Select!.." . mysqli_error($link));
$result = mysqli_query($link, $query);
?>
<?php
$count = mysqli_num_rows($result);
if ($count >= 1) {
$greeting = "<h3>Your shirt order has been submitted - THANKS!</h3><br><br>";
$hidebtn = "hidden";
}
else {
$greeting = "<h3>Submit your shirt order:</h3><br><br>";
$hidebtn = "submit";
}?>
<form method="post" action="saveadd_callaway.php" enctype="multipart/form-data">
<?php echo $greeting;?>
<div class="col-sm-3"><h1>STYLE:</h1><br>
<select name="cStyle" id="cStyle">
<option value="Mens">Mens</option>
<option value="Ladies">Ladies</option>
</select>
</div>
<div class="col-sm-3"><h1>SIZE:</h1><br>
<select name="cSize" id="cSize">
<option value="S">Small</option>
<option value="M">Medium</option>
<option value="L">Large</option>
<option value="XL">X-Large</option>
<option value="2X">XX-Large</option>
<option value="3X">XXX-Large</option>
<option value="4X">XXXX-Large (Mens Only)</option>
</select>
</div>
<div class="col-sm-3"><h1>COLOR:</h1><br>
<select name="cColorChoice" id="cColorChoice">
<option value="Parakeet">Green</option>
<option value="Black">Black</option>
<option value="Griffen Grey">Gray</option>
<option value="Paradise Pink">Pink-Coral</option>
<option value="Bright White">White</option>
<option value="Paisley Purple">Purple</option>
<option value="Birds of Paradise Orange">Orange</option>
<option value="Blue Atoll">Bright Blue</option>
<option value="Riviera Blue">Riviera Blue</option>
<option value="Peacoat Navy">Navy Blue</option>
</select>
</div>
<br style="clear: left" /><br><br><br>
<input type="hidden" name="cNetworkID" value="<?php echo $user;?>">
<input type="hidden" name="SubmittedOn" value="<?php echo date("Y-m-d h:i:sa");?>">
<input type="<?php echo $hidebtn;?>" name="submit" value="submit">
</form>
另一个......
<!--saveaddcallaway.php-->
<?php
$cStyle = $_POST['cStyle'];
$cSize = $_POST['cSize'];
$cNetworkID = $_POST['cNetworkID'];
$ColorChoice = $_POST['cColorChoice'];
$SubmittedOn = $_POST['SubmittedOn'];
echo ($cStyle . " - " . $cSize . " - " . $ColorChoice . " - " . $cNetworkID . " - " . $SubmittedOn);
/* *********************************************************************
$sql1 = "INSERT INTO tblCallaway (NetworkID,Style,Size,ColorChoice,SubmittedOn) VALUES ('$cNetworkID','$cStyle','$cSize','$ColorChoice','$SubmittedOn')";
if(mysqli_query($link, $sql1)){
echo "Shirt Order Successfully Submitted!";
header("Location: callaway.php"; // Redirect browser
} else{
echo "ERROR: Could not able to execute $sql1. " . mysqli_error($link);
}
********************************************************************* */
当它决定它不想工作时...你在提交后得到以下内容,在saveaddcallaway.php ...
Notice: Undefined index: cStyle in E:\Inet\saveadd_callaway.php on line 10
Notice: Undefined index: cSize in E:\Inet\saveadd_callaway.php on line 11
Notice: Undefined index: cNetworkID in E:\Inet\saveadd_callaway.php on line 12
Notice: Undefined index: cColorChoice in E:\Inet\saveadd_callaway.php on line 13
Notice: Undefined index: SubmittedOn in E:\Inet\saveadd_callaway.php on line 14
- - - -
即使我使用isset(),所有这一切都没有告诉我通知细节(未定义的索引......)我仍然会收到错误。为什么它有时会起作用,而不是其他的?即使我收到错误 - 我可以点击刷新,然后它就可以了!那怎么样?
答案 0 :(得分:0)
试试这个
<!--saveadd_callaway.php-->
<?php
// checks if the request is by post method and $_POST array have some values
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (count($_POST)>0)){
// get all post data
// insert into database
}else{
header("Location: callaway.php");
exit;
}