0

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

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34

4 Answers4

1

Try

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

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

Vuk Stanković
  • 7,864
  • 10
  • 41
  • 65
1

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"];
}
1

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.

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39
0

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
Morphine
  • 158
  • 1
  • 12