0

I am getting this error. Anyone please help. I am new to PHP.

Array ( [avatar] => Array ( [name] => Icon.jpeg [type] => image/jpeg [tmp_name] => C:\xampp\tmp\phpE3B9.tmp [error] => 0 [size] => 3687 ) )

 <?php
    session_start();
    $_SESSION['message']='';
        $con = mysqli_connect("localhost","root","");

            if(!mysqli_select_db($con,"smart")) //Database connected.
            {
              echo 'Database not selected';
            }
            else{
                $mysqli = new mysqli("localhost", "root", "", "smart");
                }
    if($_SERVER['REQUEST_METHOD']=='POST'){
      //Two Passwords should be equal to each other
      if($_POST['password']==$_POST['confirmpassword']){

        print_r($_FILES);die;
        $username =$mysqli->real_escape_string($_POST['username']);
        $email=$mysqli->real_escape_string($_POST['email']);
        $password = md5($_POST['password']);//md5 hash password security
        $avatar_path= $mysqli->real_escape_string('images/'.$_FILES['avatar']['name']);

        //make sure file type is image.
        if(preg_match("!image!", $_FILES['avatar']['type'])){
            //Now copy image to images folder.
          if(copy($_FILES['avatar']['tmp_name'], $avatar_path)){

               $_SESSION['username']=$username;
               $_SESSION['avatar']=$avatar_path;
               $sql= "INSERT INTO users(username,email,password,avatar)"."VALUES('$username','$email','$password','$avatar_path')";
               //if the query is successful, redirect to welcome.php page.
               if($mysqli->query($sql)==true){
                $_SESSION['message']="Registeration successful! Added $username to the database!";
                header("location:welcome.php");
               }
               else{
                $_SESSION['message']="User could not be added to the database!";
               }
          }
          else{
            $_SESSION['message']="File Upload failed!";
          }
        }
        else{
          $_SESSION['message']="Please only upload GIF,PNG or JPEG images!";
        }
      }
      else{
        $_SESSION['message']="Two passwords do not match!";
      }
    }

    ?>



    <link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="form.css" type="text/css">
    <body background="About.png">
    <div class="body-content">
      <div class="module">
        <h1>Create an account</h1>
        <form class="form" action="form.php" method="post" enctype="multipart/form-data" autocomplete="off">
          <div class="alert alert-error"><?= $_SESSION['message'] ?></div>
          <input type="text" placeholder="User Name" name="username" required />
          <input type="email" placeholder="Email" name="email" required />
          <input type="password" placeholder="Password" name="password" autocomplete="new-password" required />
          <input type="password" placeholder="Confirm Password" name="confirmpassword" autocomplete="new-password" required />
          <div class="avatar"><label>Select your avatar: </label><input type="file" name="avatar" accept="image/*" required /></div>
          <input type="submit" value="Register" name="register" class="btn btn-block btn-primary" />
        </form>
      </div>
    </div>
    </body>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • What error? `die` will cause the script to stop – frz3993 Apr 27 '17 at 17:52
  • MD5 is not sufficient for password hashing. Use [`password_hash()`](http://us3.php.net/manual/en/function.password-hash.php) and [`password_verify()`](http://us3.php.net/manual/en/function.password-verify.php) instead. – Alex Howansky Apr 27 '17 at 17:54
  • Your code is likely vulnerable to [**SQL injection attacks**](https://en.wikipedia.org/wiki/SQL_injection). You should use [**mysqli**](https://secure.php.net/manual/en/mysqli.prepare.php) or [**PDO**](https://secure.php.net/manual/en/pdo.prepared-statements.php) prepared statements with bound parameters as described in [**this post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – Alex Howansky Apr 27 '17 at 17:55
  • can you capture all of error message? – keronconk Apr 27 '17 at 18:01
  • remove the line "print_r($_FILES);die;" – Manuel Otto Apr 27 '17 at 18:03
  • got the answer ? – melvin May 25 '18 at 13:41

0 Answers0