简体   繁体   中英

why am i getting undefined indexs when i use enctype=“multipart/form-data”

why am I getting undefined index's with my form is it because of the encoding type I am using, if so what can I do to fix this to properly post my variables

<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 being posted from say page1 to this form are coming through because I have an if statement with an isset() for the variables making it header to another page if there not set. this form code is from page2

im using this code on page3 to recieve the form data

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

So when I post all the 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 that all my methods are using post, the only thing I can think of why this isnt working is because of some sort of combination of echoing input values and the enctype. If anyone could help me out it would be greatly appreciated.

Undefined variable university means you didnt select any options to fix that you can set any of the ptions to selected and for hidden variables problem is value is not there. fixed code is 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> 

I Have Any Two option
First:

error_reporting(0);

Second:

<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"]; }?>">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM