0

I have a problem with $_POST. I am adding data to my mysql database with this code and it is working.;

if (isset($_POST["d_kayit"])){
     $denetci=$dbpdo->prepare("INSERT INTO denetciler(name,pass) VALUES(:name, :pass)");
     $denetci->bindParam(":name",$_POST["denad"],PDO::PARAM_STR);
     $denetci->bindParam(":pass",$_POST["sif"],PDO::PARAM_STR);
     $denetci->execute();
}

But in the same form i want to use $_POST["denad"] for another insert. It is giving me "Notice: Undefined index: denad in" error. Sample code that giving error is;

if (isset($_POST["add"]))
{
    echo "Person: ".$_POST["denad"];
}

Can you help me please?

Sudheesh Singanamalla
  • 2,283
  • 3
  • 19
  • 36
  • 2
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – iainn Feb 04 '18 at 13:13
  • it is not duplicated question. I have looked before ask. If I dismiss something please show me. – Hüseyin Çiftçi Feb 04 '18 at 13:16
  • You are checking whether `add` is in the post array and read data from `denad`. So why do you check for one key and then read another? – Nico Haase Feb 04 '18 at 13:33
  • i have a button. i am checking if button is pushed. if button pushed i am tring to read the text. – Hüseyin Çiftçi Feb 04 '18 at 13:37

1 Answers1

0

If this:

if (isset($_POST["add"]))
{
    echo "Person: ".$_POST["denad"];
}

is yielding notice: Undefined index: denad then you probably don't have inputs "add" and "denad" on the same form. Or it is an unchecked checkbox.

Edit based on the code of your HTML form. You'll need something like this, you can't end your form with </form> like you did until you included all needed input fields:

<form action="" method="post">
    <!-- content here -->
    <input name="denad" id="denad" type="text" style="margin-top:2px; width:200px; height:30px;"></input>
    <input type="submit" class="get_file" id="K_ekle" name="add" onclick="test()" value="Kişiye Ekle" style="float:left;"></input>                    
    <!-- more content here -->
 </form>
Herco
  • 377
  • 2
  • 9