I try writing code to upload and second image and result is save in the database but when upload the pictures in folder images takes only one with name eg. 1.jpg2
Code Normal:
Upload.php
<form enctype="multipart/form-data" action="save_data.php" method="POST">
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>
Photo2: <input type="file" name="photo2"><br>
<input type="submit" value="Add">
</form>
Save_data.php
<?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']);
$pic2=($_FILES['photo2']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
mysql_select_db("test_db") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic', '$pic2')") ;
//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['photo']['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.";
}
?>
View.php
<?php
// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
mysql_select_db("test_db") or die(mysql_error()) ;
$select_all="SELECT * FROM employees";
$select_all_query=mysql_query($select_all) or mysql_error();
$select_all_count=mysql_num_rows($select_all_query) or mysql_error();
$i=0;
while ($select_all_count > $i ) {
$out_name=mysql_result($select_all_query,$i,"name");
$out_email=mysql_result($select_all_query,$i,"email");
$out_phone=mysql_result($select_all_query,$i,"phone");
$out_photo=mysql_result($select_all_query,$i,"photo");
$out_photo2=mysql_result($select_all_query,$i,"photo2");
$i++;
echo ("$out_name<br />");
echo ("$out_email<br />");
echo ("$out_phone<br />");
echo ("<img src='http://127.0.0.1/upload/test/images/$out_photo' width='10%'><br />");
echo ("<img src='http://127.0.0.1/upload/test/images/$out_photo2' width='10%'><br /><br />");
}
?>
Certainly the change will want to Save_data.php :/