Forgive me if I'm doing this wrong. I use this site 5 days a week to help me, but this is the first time I've actually posted a question. I'm self-taught b/c I was dumped into maintaining a php site. I know enough to be dangerous but not enough of the right way (yet). So please be kind when you feel the need to comment "WTF is this chick doing?!?!?" :)
The Gist: I have 2 files: callaway.php & saveaddcallaway.php. callaway.php connects to mysql db and checks is the user (who is already logged in) already has a record in a table called tblcallaway. If they don't, then they have a form available for them to submit a shirt order with their size, style and color. On submit, that form action passes the variables to saveaddcallaway.php which then echos the user's selections.
Really...On submit, that form action passes the variables to saveaddcallaway.php which then inserts the order into the tblcallaway and redirects the user back to callaway.php with a "Your order has been submitted" message. But for the purpose of this problem - we're just going to pretend that displaying the selections is what I need.
The Problem: It only works sometimes. You can submit and all works great. Then if you or anyone else tries to submit, it may or may not work. When it doesn’t work, you get the “Undefined Index” errors…BUT if you click the webpage refresh button a couple times, it will show your selections! It’s like the callaway.php only processes the form selections when it wants. It’s very sporadic in when it works and when it doesn’t work. I've tried different combinations of sizes/colors/styles. We’ve rebooted the server. And it’s still only working … sometimes. **Just a side note*: When it’s set to insert into tblcallaway it inserts all blanks values in the record. I've included the code, commented out, but the issue is before it gets put into the table (I think). Figured I'd include it anyways!
<!--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>
And the other...
<!--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);
}
********************************************************************* */
And when it decides it doesn't want to work... you get the following after submit, on the 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
- - - -
Even if I use isset() all that does is not show me the Notice details (Undefined index...) I still get an error. Why does it work sometimes, but not others? Even when I get an error - I can click refresh and then it works! How is that?