PHP错误:这些PHP代码有什么问题? 它说未定义的索引错误[重复]

My code:

$name=$_POST["name"];

This is the error

Notice: Undefined index: name in /home/u615903880/public_html/reg3.php on line 4

code :

<?php
$con          = new mysqli("xxxxx", "xxxx", "xxxx");
$name         = $_POST["name"];
$username     = $_POST["username"];
$emailaddress = $_POST["emailaddress"];
$password     = $_POST["password"];
$statement    = mysqli_prepare($con, "INSERT INTO users (name, username, emailaddress, password)VALUES (?,?,?,?)");
mysqli_stmt_bind_param($statement, "ssss", $name, $username, $emailaddress, $password);
mysqli_stmt_execute($statement);
$response            = array();
$response["success"] = true;
echo json_encode($response);
mysqli_stmt_close($statement);
mysqli_close($con);
?>

Error lines 4,5,6,9,10,14

</div>

Try

$name = isset($_POST['name']) ? $_POST['name'] : 'nothing provided';

You can put anything instead of 'nothing provided' like NULL or something

Its Notice not an error:

you can use

error_reporting(1);

on top of page this will hide warnings and notices.

or you can use code this way

if(isset($_POST["name"])){
 $name=$_POST["name"];
}

You didn't send a POST variable called name. If it was from an HTML form, make sure the input is not disabled or it won't post. Also, make sure your form field has a name and not just an id, as it is the name that is used in a post request:

<input type="text" id="notused" name="used" />

In which case $_POST['used'] would work upon submission.

I suspect the key 'name' is not defined in the $_POST array. to check for missing key you could use:

$name = $_POST["name"]??null; // PHP /7+

or

$name = isset($_POST["name"])?$_POST["name"]:null; // older