i am developing register form using php where i need to upload the file its not uploading
$firstname=$_REQUEST['firstname'];
$lastname=$_REQUEST['lastname'];
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$email=$_REQUEST['email'];
$Image=basename($_FILES['file']['name']);
$Image=str_replace(' ','|',$Image);
if($firstname && $lastname && $username && $email)
{
require 'dbconnect.php';
$query="select * from members where email='$email'";
$result=mysql_query($query);
$exists=mysql_num_rows($result);
if($exists>0)
{
$message=array("message"=>"email already existed");
echo json_encode($message);
}
else
{
if($Image)
{
$Image=date("YmdHis").".jpg";
$target_path="userimages/".$Image;
move_uploaded_file($_FILES["file"]["tmp_name"],$target_path);
$query="INSERT INTO `members`
(`username`, `firstname`, `lastname`, `email`, `password`, `image`) VALUES
('$username', '$firstname', '$lastname', '$email', '$password', '$Image')";
}
else
{
$query="INSERT INTO `members` (`username`, `firstname`, `lastname`, `email`, `password`) VALUES
('$username', '$firstname', '$lastname', '$email', '$password')";
}
$result=mysql_query($query);
}
}
html code is
<html>
<form action="register.php" method="post" enctype="multipart/form-data">
<div>firstname<input type="text" name="firstname"></div>
<div>lastname<input type="text" name="lastname"></div>
<div>username<input type="text" name="username"></div>
<div>password<input type="text" name="password"></div>
<div>email<input type="text" name="email"></div>
<div>image<input type="file" name="file"></div>
<div><input type="submit" name="submit"></div>
</form>
</html>
in this i upload image but its not uploaded to server and also to database in this else condition is exicuted
please help me
Check the permissions on the folder you are trying to write to – if the image is not being uploaded and the
move_uploaded_filefails, then the row won’t be inserted into the database at all.For comparison, here’s some code from an app I use to upload a file to the server:
My form looks something like: