0

I am using following code to UPDATE database and upload file. It updates fields in database name,email,phone.
But query does not work for photo field. It gives error. And considers '$pic' as empty.

Help Plz.

Database

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30))
<?php 
 
 //This is the directory where images will be saved 
 $target = "images/"; 
 $target = $target . basename( $_FILES['photo']['name']); 
 
 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 
 $id=$_POST['id'];

 // Connects to your Database 
 mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ; 
 mysql_select_db("Database_Name") or die(mysql_error()) ; 
 
 //Writes the information to the database 
$sql="UPDATE `employees` SET name='$name',email='$email',phone='$phone',photo='$pic' WHERE id='$id' "; 
 $result=mysql_query($sql); 
 
 //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."; 
 } 
 ?>
3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by vizz
0

Hi

//Writes the information to the database 
$sql="UPDATE `employees` SET name='$name',email='$email',phone='$phone',photo='$pic' WHERE id='$id' "; 
 $result=mysql_query($sql);

Please try the below one

$sql="UPDATE `employees` SET name='$name',email='$email',phone='$phone',photo='$pic' WHERE id='$id' ";
mysql_db_query($database,$sql);
	$change=$_POST["id"];
0

Thanks.

Hi

//Writes the information to the database 
$sql="UPDATE `employees` SET name='$name',email='$email',phone='$phone',photo='$pic' WHERE id='$id' "; 
 $result=mysql_query($sql);

Please try the below one

$sql="UPDATE `employees` SET name='$name',email='$email',phone='$phone',photo='$pic' WHERE id='$id' ";
mysql_db_query($database,$sql);
	$change=$_POST["id"];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.