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 " ";
}
}
}
?>