Hi all, I'm new to PHP and have been trying for the last 4 hours to get a script working. A thumbnail appears in the upload.php page, but nothing is registering in the table.
If anyone can help I would appreciate it so much, it will stop my laptop from flying out the window.
here is my code for the upload form
<?php
include 'dbc.php';
page_protect();
$_SESSION['id_user'] = $_POST['id_user'];
$_SESSION['firsttime']= "ok";
?>
<style type="text/css">
<!--
.style2 {font-size: 36px}
-->
</style>
<body bgcolor="#FF6699">
<div align="center">
<p><br />
</p>
<p><br />
<br />
</p>
</div>
<center>
<p>Choose the image you want to upload, The image must be less than 100 kb in size.</p>
<form action="upload.php" enctype="multipart/form-data" method="POST">
<input name="id_user" type="hidden" value="<?php echo $_SESSION['id_user']; ?>" />
<table width="95%" border="0">
<tr>
<td>Select a file:</td>
<td><input type="file" name="user_file" size="50"></td>
</tr>
<tr>
<td>Title</td>
<td><input name="title" type="text" id="title" size="40"/></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="description" cols="40" rows="4" id="description"></textarea></td>
</tr>
<tr>
<td>Tags</td>
<td><input name="image_tags" type="text" id="image_tags" size="40"/>
(seperate tags by comma) </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Upload Now" /></td>
</tr>
</table>
<p><br />
<br />
</p>
</form>
<br><h2><a href='library.php'>View Images Library</a></h2>
</center>
and this is the code to process the upload
<?php
include 'dbc.php';
page_protect();
$_SESSION['id_user'] = $_POST['id_user'];
$n=$_FILES['user_file']['name'];
$type=$_FILES['user_file']['type'];
$size=$_FILES['user_file']['size'];
$time=time();
$n=$time;
$path="uploads\\". $n;
$uploaded = $_SESSION['firsttime'];
if ($uploaded== 'ok')
{
if ($size<100000 && preg_match("/image/", $type) )
{
move_uploaded_file($_FILES['user_file']['tmp_name'],
$path);
$path2=$root . $n;
echo "<center>";
echo "<h3>Your Image Link Is: </h3><a href=$path2>$path2</a><br><br>";
echo "<br>";
echo "<img src=$path2 border='5' height='100' width='100'></img>";
echo "<center>";
$link=mysql_connect("localhost", "heritage1", "heritage1")
or die("couldn't connect to database");
mysql_select_db("heritage1") or die("Could not select database");
$query = "INSERT INTO image_table (image, title, description, image_tags) VALUES ('$path2', '$_POST[title]', '$_POST[description]', '$_POST[image_tags]')";
$result = mysql_query($query);
echo "1 record added";
//session_destroy();
}
}
else
{
echo "you couldnt upload the same image many times per session go back and choose it or another one";
}
////////////
if ($size>1000000)
{
echo "ERROR <br> the image size is too big<br>";
}
if (!preg_match("/image/",$type) )
{
echo "ERROR <br> the file is not image<br>";
}
echo"<br><br><h2><a href='library.php'>View Images Library</a></h2>";
echo "<body bgcolor='#FF6699'>";
?>