-5

if i write code php same:

<?php

$title = strip_tags($_POST['title']);

?>

unknown error show!

Notice: Undefined index: title in C:\xampp\htdocs\file.php on line 3

Horby
  • 45
  • 6

2 Answers2

0

$_POST has value, after submitting form, so before that anybody can't use $_POST ..

   <?php
         if(isset($_POST['title'])){  
//Here in condition if(array_key_exists ( 'title' , $_POST )) can also be checked... 
//OR if(!empty($_POST)) OR if(!empty($_POST['title'])) can also be put..
            $title = strip_tags($_POST['title']);
         }
        ?>
Shaunak Shukla
  • 2,347
  • 2
  • 18
  • 29
0

If both form and action in the same page, the first load will show error as there is no data posted. So first checj whether a POST has been made and then assign. Try this

$title = "";
if(isset($_POST['title'])){
    $title = strip_tags($_POST['title']);
}
Arun
  • 3,640
  • 7
  • 44
  • 87