0

Hi, why use with table error? if not use witn table are normal... can u help ???

<form method="post" action="page.php">
<table>
 <tr>
  <td>Select</td>
  <td>
   <select name="people" id="people">
    <?php if($_POST['submitted'] == true){ ?>
        <option value="<?php echo $_POST['people']; ?>" selected="selected"><?php echo $_POST['people']; ?></option>
    <?php }else{ ?>
      <option value=""> -- select -- </option>
    <?php } ?>
       <option value="" disabled="disabled"> -------- </option>
       <option value="Person 1">Person 1</option>
       <option value="Person 2">Person 2</option>
   </select>
  </td>
 </tr>
 <tr>
  <td></td>
  <td>
   <input type="submit" id="submit" name="submit" value="Submit" />
   <input type="hidden" name="submitted" id="submitted" value="true" />
  </td>
 </tr>
</table>
</form>
3
Contributors
6
Replies
19
Views
3 Years
Discussion Span
Last Post by sokborey.chea
0

look the image below... when i used with table

Notice: Undefined index: submitted in C:\wamp\www\Untitled-1.php on line 7

Edited by sokborey.chea: forget somethings

Attachments error.JPG 29.99 KB
1

The table has nothing to do with it.

this is the one causing the error

 <?php if($_POST['submitted'] == true){ ?>

you can do something like this

<?php if(isset($_POST['submit']) && ($_POST['submitted'] == true)){ ?>
0

really thz for ur help @veedeoo :)

i have one more question for ask u...

if i use <?php if(isset($_POST['submit'])){ ?>

why need add ($_POST['submitted'] == true) can u explain this?

Edited by sokborey.chea: i some question for ask abut his post...

1

Sorry about this

 ($_POST['submitted'] == true)

It was my mistakes. It should be like this

 ($_POST['submitted'] == "true")

It should have double quotes, because it is a string and that's what I wanted to confirm . So the correct codes should be like this

    <?php if(isset($_POST['submit']) && ($_POST['submitted'] == "true")){ ?>

Now, that I have corrected my wrong response, I have to answer your question.

why need add ($_POST['submitted'] == true) can u explain this?

Normally, when we assign hidden attribute to a form input, it is for the purpose of second stage validation e.g. we want make make sure that it is not a robot filling and submitting our form. So, this

 <input type="hidden" name="submitted" id="submitted" value="true" />

can be confirmed by my proposed codes above. Another purpose is to prevent repeated form submission of the same user.

Edited by veedeoo: more info added

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.