I want to process form input into a MYSQL database but I am having trouble getting other files to recognize data in the _POST array and keep getting the typical "Undefined index" error. My form:
<?php
$category = '';
$item = '';
// Check if form is posted
if (isset($_POST['item'])){
// Declare POST'd values into variables
$category = $_POST['Category'];
$item = $_POST['item'];
}
?>
<!-- Item Input form -->
<form id='additem' method='post' action="">
<fieldset>
<legend>Add Item</legend>
<table>
<tr>
<td><label for='Category'>Category: </label></td>
<td><input type='text' name='Category' list='categories' value='<?php $category;?>' /></td>
<datalist id='categories'>
<option value='Protein'>
<option value='Produce'>
<option value='Baked Goods'>
<option value='Dry/Canned'>
<option value='Household'>
</datalist>
</tr><tr>
<td><label for='item'>Name: </label></td>
<td><input type='text' name='item' value='<?php $item;?>' /></td>
</tr><tr>
<td></td><td><input type='Submit' value='Submit' /></td>
</tr>
</table>
</fieldset>
</form>
When I use $_POST in this file, it works perfectly fine but when I try to use it in another file, process.php:
<?php
echo $_POST['Category'];
echo '<br>';
echo $_POST['item'];
?>
it gives: Notice: Undefined index: Category in E:\Documents\XAMPP\htdocs\Website\process.php on line 3 Notice: Undefined index: item in E:\Documents\XAMPP\htdocs\Website\process.php on line 5
Now I know my _POST array is not empty, because I can access it within my original form file. If I change the form action to "process.php" it works, but also automatically takes me to that page. What I want is for process.php to send data to my database while the form returns to its own page ready for more input. I have even literally copy and pasted the code from that example into files and attempted to run those, but I get similar errors so I think it might be an issue with XAMPP/Apache.
To address this, I have also tried this but post_max_size was already set to 8M, and as per another post I saw somewhere I added 'variables_order = "EGPCS"' in the line below. Still I am getting the same undefined index.
Is there something wrong with my code? Is it XAMPP/Apache? I have tried fresh installing XAMPP, but the issue still persists.