-2

So I'm trying to create a simple sign up the program that inserts the data into a MySQL database:

<?php


$first=$_POST['name'];
$last=$_POST['lname'];
$uname=$_POST['uname'];
$pass=$_POST['pass'];

if(empty($first) || empty($last) || empty($uname) || empty($pass))
{
    header('Location: redirect.php');
}
else
{
    $conn=new mysqli("localhost", "root", "", "login");

    if($conn->connect_error)
    {
        die("We've lost the connection because of ".$conn->connect_error);
    }

    $insert="INSERT INTO people (name, lastname, username, pass) VALUES ('$name', '$last', '$uname', '$pass')";
    $conn->query($insert);
}

?>

However when i run the program and insert the data I get the error:

Notice: Undefined variable: name in C:\xampp\htdocs\vtor\sign_up.php on line 27

line 27 is this line:

$insert="INSERT INTO people (name, lastname, username, pass) VALUES 
('$name', '$last', '$uname', '$pass')";

Any ideas?

ndrwnaguib
  • 5,623
  • 3
  • 28
  • 51
David Mathers
  • 163
  • 2
  • 7

2 Answers2

1

$name should be called $first as set at the top of the script. Change

VALUES ('$name', '$last',

to

VALUES ('$first', '$last',

Juakali92
  • 1,155
  • 8
  • 20
0

You do not define a variable called name, but only a variable called first

Briomkez
  • 567
  • 3
  • 17