<?php
$conn = mysqli_connect('localhost', 'root', '', 'myapp');
$msg = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $image = $_FILES['image']['name'];
    $tmp = $_FILES['image']['tmp_name'];

    if ($name && $email && $password && $image) {
        if (!is_dir('uploads')) {
            mkdir('uploads');
        }
        $path = 'uploads/' . time() . '_' . $image;
        move_uploaded_file($tmp, $path);

        $q = "INSERT INTO image_table (name,email,password,profile_image) VALUES ('$name','$email','$password','$path')";
        if (mysqli_query($conn, $q)) {
            header('Location: login.php');
            exit;
        } else {
            $msg = 'Error saving data';
        }
    } else {
        $msg = 'Please fill all fields';
    }
}
?>
<!DOCTYPE html>
<html>
<head><title>Register</title></head>
<body>
<h2>Register</h2>
<form method="post" enctype="multipart/form-data">
Name: <input type="text" name="name"><br><br>
Email: <input type="email" name="email"><br><br>
Password: <input type="password" name="password"><br><br>
Profile Image: <input type="file" name="image"><br><br>
<input type="submit" value="Register">
</form>
<p style="color:red;"><?php echo $msg; ?></p>
<a href="login.php">Login</a>
</body>
</html>
