0

I am new to PHP. My code shows error undefined variable row on the line $useruid=$row['id'] I can't understand where I did wrong

<?php
include 'header.php';
?>
<?php
    $db = mysqli_connect("localhost", "root", "", "discount");
    $msg = "";

    if (isset($_POST['register'])) {


        $mname = $_POST['mname'];

      $password = $_POST['password'];
            $sql= "INSERT INTO merchantl (mname, password) VALUES ('$mname', '$password')";
            mysqli_query($db,$sql);
  $insert="SELECT * FROM merchantl where mname='$mname'";
    $result=mysqli_query($db,$insert);
    if(mysqli_num_rows($result)>0){
        while($row=mysqli_fetch_assoc($result)){
            $useruid=$row['id'];
            $usern=$row['mname'];
            $sql="INSERT INTO shop (userid,promo) VALUES('$useruid','click here to avail offer')";
            if (mysqli_query($db, $sql)) {
      header('location:merchantlogin.php?registration=success');
    } else {
        echo "error";
    }
        }
    }
        }
?>
Farzad Vertigo
  • 2,458
  • 1
  • 29
  • 32
  • 3
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) –  Jan 22 '19 at 05:07
  • 1
    Multiple things are wrong here... Presumed correct execution of functions, plain text passwords, user data to SQL (which opens you to SQL injections, pair that with the plaintext passwords). `location:merchantlogin.php?registration=success` is also not likely to work, and if it did you should `exit` after that call. – user3783243 Jan 22 '19 at 05:16
  • i will hash it later but the error keeps on annoying – Dhruv Patel Jan 22 '19 at 05:18
  • You should have at least 2 notices in that case, `$usern` should throw the same notice. Don't use `md5` or `sha`s use `password_hash`. There also are 3 other issues in that comment – user3783243 Jan 22 '19 at 05:21

0 Answers0