0

hi guys,

i saw same article with my problem, but i seem dont get the solution. the code works but some notice error.

i have problem: "Notice: Undefined index:" Line: 40 // basename($_FILES['uploadedfile']['name'])

the Code:

<?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']); 

 // Connects to your Database 
// mysql_connect("localhost", "root", "pw", "test") or die(mysql_error()) ; 
// mysql_select_db("Database_Name") or die(mysql_error()) ; 


    $con = mysqli_connect("localhost", "root", "pw", "test");
    if(mysqli_connect_errno())
    {
        echo "error connection" . mysqli_connect_error();
    }

 //Writes the information to the database 
  //(id, name, email, phone, pic) did not use this
 $sql = "INSERT INTO employees VALUES ('$id', '$name', '$email', '$phone', '$pic')" ; 


 if(!mysqli_query($con, $sql))
{
    die('Error ' . mysqli_error());
}
echo "1 Data added";

 //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 "<br>Sorry, there was a problem uploading your file."; }

 mysqli_close($con);
 ?> 

Please help. Thanks in advance.

2
Contributors
2
Replies
11
Views
4 Years
Discussion Span
Last Post by earlxph8
0

basename($_FILES['photo']['name']); and basename($_FILES['uploadedfile']['name']).

0

i think i have the answer, but i dont know if this is the correct one, i use basename( $_FILES['photo']['name']) instead of basename( $_FILES['uploadedfile']['name']). thanks

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.