Why am I getting undefined indices when I use enctype = "multipart / form-data"

why am i getting undefined index with my form is it because of the type of encoding i am using, if so what can i do to fix it to place my variables correctly

<form enctype="multipart/form-data" name="pmForm" id="pmForm" method="post"                action="personalspage.php"><br>
<b>Age</b> <input type="text" name="age" id="age" cols="4"><br><br>
<b>University</b> <select name="university" id="university" onfocus="emptyElement('status')">
                    <option disabled selected>select one...</option>
                    <option value="Algoma">Algoma University</option>
                    <option value="york">York University</option>
                 </select><br><br>
<b>Headline</b> <input type="text" name="headline" id="headline"><br><br>
<b>Message</b> <textarea name="message" id="message" rows="6" cols="50"></textarea><br><br>
<b>Add a picture</b> <input type="file" name="photo" id="photo" accept="image/*"><br><br>
<input type="hidden" name="mysex" id="mysex" value="<?php echo $_POST["mysex"]; ?>">
<input type="hidden" name="lookingfor" id="lookingfor" value="<?php echo $_POST["lookingfor"]; ?>">
<center><input type="submit" name="adSubmit" id="adSubmit" value="Post It"></center>
</form>   

      

I know that the variables that are submitted from say page1 to this form get through because I have an if statement with isset () for variables that make it a heading on another page if not set. this form code is on page2

im using this code on page 3 to get the form data

$mysex = $_POST['mysex'];
$lookingfor = $_POST['lookingfor'];
$uni = $_POST['university'];

      

So when I submit the entire variable from this form to another page, I get

Notice: Undefined index: mysex in C:\xampp\htdocs\Website\personalspage.php on line 4

Notice: Undefined index: lookingfor in C:\xampp\htdocs\Website\personalspage.php on line 5

Notice: Undefined index: university in C:\xampp\htdocs\Website\personalspage.php on line 6

      

I double checked and made sure all my methods are using the message, the only thing I can think of as to why this is not working is some kind of combination of echo input and enctype. If anyone could help me it would be greatly appreciated.

+3


source to share


2 answers


Undefined variable university means that you have not selected any parameters to fix that you can set for any of the ptions in selected

, and there is no value for the hidden variable problem. fixed code here



<form enctype="multipart/form-data" name="pmForm" id="pmForm" method="post"                action="personalspage.php"><br>
<b>Age</b> <input type="text" name="age" id="age" cols="4"><br><br>
<b>University</b> <select name="university" id="university" onfocus="emptyElement('status')">
                    <option disabled selected value="" selected>select one...</option>
                    <option value="Algoma">Algoma University</option>
                    <option value="york">York University</option>
                 </select><br><br>
<b>Headline</b> <input type="text" name="headline" id="headline"><br><br>
<b>Message</b> <textarea name="message" id="message" rows="6" cols="50"></textarea><br><br>
<b>Add a picture</b> <input type="file" name="photo" id="photo" accept="image/*"><br><br>
<input type="hidden" name="mysex" id="mysex" value="<?php if(isset($_POST["mysex"])) echo $_POST["mysex"];else echo ""; ?>">
<input type="hidden" name="lookingfor" id="lookingfor" value="<?php if(isset($_POST["lookingfor"]))echo $_POST["lookingfor"];else echo ""; ?>">
<center><input type="submit" name="adSubmit" id="adSubmit" value="Post It"></center>
</form> 

      

0


source


I have two options
First:

error_reporting(0);

      



Secondly:

<input type="hidden" name="mysex" id="mysex" 
value="<?php if(isset($_POST["mysex"])){ echo $_POST["mysex"]; }?>">
<input type="hidden" name="lookingfor" id="lookingfor" 
value="<?php if(isset($_POST["lookingfor"])){ echo $_POST["lookingfor"]; }?>">

      

-1


source







All Articles