0

I'm new in PHP and I'm getting this error

"Notice: Undefined index:...on line 58"

I have used similar method to write PHP code on my previous HTML elements e.g. radio button, input form and it run smoothly, but why it doesn't work on select option

<?php
     include "connection.php";
     if(isset($_POST['submit'])) {
     $submit = mysqli_query($conn, "INSERT INTO tb_registration VALUES
      ( '".$_POST['FULLNAME']."',                      
        '".$_POST['EDUCATION']."',                      
        '".$_POST['ACTIVITY']."',
        NULL )");
      }
 ?>

<div>
 <label>FULLNAME</label>
 <input type="text" name="FULLNAME" />
</div>

<div>
  <input type="radio" name="EDUCATION" value="EDUCATION">
   <label>Bachelor</label>    
</div>
<div>
  <input type="radio" name="EDUCATION" value="EDUCATION">
   <label>Master</label>      
</div>

<div>
  <select name="ACTIVITY">
    <option value="A1">Dancing</option>
    <option value="A2">Swimming</option>
  </select>
</div>

i expect error line does not appear anymore.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • Please read about **[SQL injection](https://en.wikipedia.org/wiki/SQL_injection)**. Instead of building queries with string concatenation, use **[prepared statements](https://secure.php.net/manual/en/pdo.prepare.php)** with **[bound parameters](https://secure.php.net/manual/en/pdostatement.bindparam.php)**. See **[this page](https://phptherightway.com/#databases)** and **[this post](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)** for some good examples. – John Conde May 13 '19 at 16:36
  • You can check this light weight class for prepared queries [here](https://github.com/danish-khan-I/php-pdo) – danish-khan-I May 13 '19 at 17:21
  • Many thanks for the reply, i'll try all suggestion above – yoga purbaya May 14 '19 at 10:46

0 Answers0