-4

I have no ideea why but i get a few errors in my PHP I have tried everything and i simply cannot get it to work,if anyone could help me a bit that would be great

Notice: Undefined index: confirmpassword in 
C:\xampp\htdocs\photographer\register\form.php on line 7

Notice: Undefined index: username in 
C:\xampp\htdocs\photographer\register\form.php on line 8

Notice: Undefined index: email in 
C:\xampp\htdocs\photographer\register\form.php on line 9

Notice: Undefined index: password in 
C:\xampp\htdocs\photographer\register\form.php on line 10

my code is

<?php
    session_start();
    $_SESSION['message'] = '';

    require_once "../db/connect.php";
    if ($_POST['password'] == $_POST['confirmpassword']) {
        $username = mysqli_real_escape_string($_POST['username']);
        $email = mysqli_real_escape_string($_POST['email']);
        $password = md5($_POST['password']);

        $query = "INSERT INTO finalx VALUES ('$username' '$password' '$email')";

        if (mysqli_query($query) == true) {
            $_SESSION['message'] = 'Inregistrare reusita';
            header("Location: welcome.php");
        }
        else {}
    }
?>
GummyGod
  • 11
  • 4
  • 1
    you better add a check ```isset($_POST['confirmpassword'])``` and try to figure out. – Moeen Basra Nov 20 '17 at 23:49
  • @MoeenBasra all my error dissapeared after doing that , can you please help me understand why the hell? – GummyGod Nov 20 '17 at 23:55
  • I guess your from is not getting submitted properly. Please make sure you are using the right url to submit the form. If it is right then simply make sure you are not getting the url with get request. Add a check ```if (!empty($_POST))``` and try again. – Moeen Basra Nov 20 '17 at 23:59

2 Answers2

0

a quick and dirty way is to test the post...right after the require_once put this

 require_once "../db/connect.php";
 if (count($_POST) == 0)
      die('Need Data to continue');
Forbs
  • 1,256
  • 1
  • 7
  • 9
0

Items you are trying to use from $_POST array are simply not defined:

  • make sure that data is actually send from your frontend,
  • validate the input data before performing any other tasks in the backend, for example with isset().