Home how to get form POST value in php
Reply: 1

how to get form POST value in php

rajkumar Published in 2018-01-13 05:15:56Z

This question already has an answer here:

  • PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” 24 answers
  • PHP Undefined Index 5 answers

I need how to get form POST value on the same page. Below is my script to try and extract the value as well as the form html:

<form action="" id ='list' name= "list" class="form-inline" method="POST">
    <div class="select">
        <select name="lamp" id ="lamp" onchange="gender(this)" style="background:transparent">
            <option id ='gender' hidden="hidden">Gender</option>
            <option value="0">Boy's</option>
            <option value="1">Girl's</option>

My Php code:

if (isset($_POST)) {  
    $pg_type =$_POST['lamp'];
    echo $pg_type;die;

I have echo the my variabe it is showing like:

Notice: Undefined index: lamp in C:\xampp\www\htdocs\rentozy\assets\includes\list-header.php on line 20

ino Reply to 2018-01-13 06:04:35Z

The form:
1. be consistent - use " or ' but not both for the HTML attributes;
2. set the name of select to gender and remove the first option since it is nonsense in this example;

<form action="" id="list" name="list" class="form-inline" method="POST">
    <div class="select">
        <select name="gender" id="gender" style="background:transparent">
            <option value="0">Boy's</option>
            <option value="1">Girl's</option>

1. change the if check to the exact key such as gender not to the whole POST array 2. To check what was actually send via POST you can print the whole array:

if (isset($_POST['gender'])) {  
    die('Gender value in $pg_type is: ' . $pg_type); // for debugging
else {
     // for debugging
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305189 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO