upload image error

xiaopeng

New Member
Ok I have a form page once clicked submit it processes add.php in div 'right' as you can see now the problem I am having is.....It processes add.php and inserts all into the database but...it doesn't insert the image url or uploads image to server,as said everything else works fine other than image in database and server.Is there any solutions?? I will put both scripts down and any solution would be great.Form page\[code\]<script type="text/javascript">jQuery(document).ready(function($) { $("#Submit").click(function() {var url = "add.php"; // the script where you handle the form input.$.ajax({ type: "POST", url: url, data: $("#myForm").serialize(), // serializes the form's elements. success: function(html){ $("#right").html(html); } });return false; // avoid to execute the actual submit of the form. });});</script></head><body><div id="right"></div><form action="add.php" method="post" enctype="multipart/form-data" id ="myForm"> Name: <input type="text" name="name"><br> E-mail: <input type="text" name = "email"><br> Phone: <input type="text" name = "phone"><br>Photo: <input type="file" name="photo"><br><input type="submit" value="http://stackoverflow.com/questions/12746558/Upload" id="Submit"></form>\[/code\]add.php\[code\]//This is the directory where images will be saved $target = "images/userimages/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $name = makesafe($_POST['name']); $email = makesafe($_POST['email']); $phone = makesafe($_POST['phone']); $pic = ($_FILES['photo']['name']); //Writes the information to the database mysql_query("INSERT INTO `Employees` VALUES ('', '$name', '$email', '$phone', '$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } \[/code\]
 
Back
Top