hi,
i am new to php. i had a problem with insertion. when i upload a file i should get the filename,uploadedby,uploadeddate,and size of the file in a table. first of all i am not getting inserted in the database itself. so can any one help me .....

--------upload.php--------

<html>
<body>
<form enctype="multipart/form-data" action="upload2.php" method="POST">
<table>
<tr>
<td><img src="Logofinalcopy.gif"></td>
</tr>
</table>
<table>
<br><br>
<tr>
	<td>
		<strong>Please choose a file: </strong>
	</td> 
	<td>
		<input name="uploaded" type="file"><br>
    </td>
</tr>
<tr><td>
<input type="submit" value="upload"></td></tr>

</table></form></body></html>
<?php
ob_start();
@session_start();
require_once ("check.php");
$con=mysql_connect("10.70.1.50","invensis","invensis");
if(!$con)
    {
             die('Could not connect: ' . mysql_error());
    }
mysql_select_db("database_myproject",$con);
 $sql= "select * from files where uploadedby='$_SESSION[username]'";
 mysql_error();
    $result=mysql_query($sql);
    $num=mysql_num_rows($result);

?>
<html>
<body>
<table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
<tr>
<th>filename</th>
<th>uploadedby</th>
<th>uploadeddate</th>
<th>size</th>
</tr>
 <?php
    $sno=1;
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
    ?>
 <tr>
 <?php $filename=$_REQUEST[i]?>
 <td><?php  echo '$filename';?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>
<td><?php echo $size ?> </td></tr>
<?php
    $sno=$sno+1;
}
?>

</table></body></html>

--------upload2.php---------------

<?php
ob_start();
@session_start();
require_once ("check.php");
$con=mysql_connect("10.70.1.50","invensis","invensis");
if(!$con)
    {
             die('Could not connect: ' . mysql_error());
    }
mysql_select_db("database_myproject",$con);
 $sql="insert into files(filename,size,uploadedby,projectid) values ('$filename','$size','$_SESSION[username]',$projectid)";
 mysql_error();
 $result = mysql_query($sql);
 $dirname=$_POST['projectname'];
 $dir="files";

    if(is_dir($dirname))
    {
        $target = "$dir/$dirname/";
        $target = $target . basename( $_FILES['uploaded']['name']) ;
        
        $ok=1; 
        if ($ok==0) 
        { 
            Echo "Sorry your file was not uploaded"; 
        } 
        else 
        { 
            if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
            { 
                echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; 
                
            } 
            else 
            { 
                echo " "; 
            } 
        }
     }
     else
     {
        $path="$dir//$dirname";
        @mkdir($path,0777,true);
        $target = "$dir/$dirname/";
        $target = $target . basename( $_FILES['uploaded']['name']);
          
        $ok=1; 
        if ($ok==0) 
        { 
            echo "Sorry your file was not uploaded"; 
        } 
        else 
        { 
            if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
            { 
                echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
                 echo '<a href="upload.php?i=$filename">Back</a>';  
            } 
            else 
            { 
                echo " "; 
            } 
        }
     }
    
       
    
?>

To check whether u have received all the fields by printing it.
echo $sql="insert into files(filename,size,uploadedby,projectid) values ('$filename','$size','$_SESSION[username]',$projectid)";

To check whether u have received all the fields by printing it.
echo $sql="insert into files(filename,size,uploadedby,projectid) values ('$filename','$size','$_SESSION[username]',$projectid)";

yes, i am getting all the fields.
but it is still not displaying the filename

Insert the code in before the insert query

$filename=$_FILES;
echo "Filename is".$filename;

Insert the code in before the insert query

$filename=$_FILES;
echo "Filename is".$filename;

i had done as u said and i got
Filename iscreation.php
insert into files(filename,size,uploadedby,projectid) values ('creation.php','','nityanand',)
The file has been uploaded Back

In your database a filename is uploaded successfully..?

In your database a filename is uploaded successfully..?

no it is not inserting in the database

how are you collecting the varibales for insertion here?

$sql="insert into files(filename,size,uploadedby,projectid) values ('$filename','$size','$_SESSION[username]',$projectid)";

If you want to collect background info from a form use input tags with type = "hidden" attributes.
You will have them in a $_POST array after a submit. If you dont want to do a form submit, I guess you could use the session cache. Otherwise the values will not survive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.