Larry
Larry

Reputation: 21

PHP POST METHOD Undefined Index

I am trying to implement the creating topic part in forum

Why I can't use the another php file, say b.php to get data that sent from a.php?

$topic=$_POST['title'];
$detail=$_POST['content'];
$name=$_POST['username'];

Errors show message that undefined index at these 3 inputs.

Upvotes: 0

Views: 2684

Answers (1)

hsz
hsz

Reputation: 152206

Because you are calling this script without sending POST data.

Use it in following way:

$topic  = empty($_POST['title'])  ? null : $_POST['title'];
$detail = empty($_POST['detail']) ? null : $_POST['detail'];
$name   = empty($_POST['name'])   ? null : $_POST['name'];

It will avoid errors and if you just request script without POSTing, variables will contain null values

Upvotes: 3

Related Questions