I have a table called picture(id, pic, date_posted). I want to insert the picture's url into the 'Pics' directory in my website from my index.php page. I used the following code:
if(isset($_POST['send'])){
//sever is already connected, and database has already been selected
$name = str_replace(" ","_",$_FILES['img']['name']);
move_uploaded_file($_FILES['img']['tmp_name'], 'Pics/'.$name);
//my sql statement that I think it doesn't work
$sql = "INSERT INTO picture(pic, date_posted) VALUES(Pics/'".$name. "', ".time().")";
$result = mysql_query($sql, $on) or die(mysql_error());
//displaying the result
$sql_dislay = "SELECT * FROM picture";
$result_display = mysql_query($sql_display, $con) or die(mysql_error());
echo "<table border=1>
<tr>
<th>ID</th>
<th>Image</th>
<th>Date Uploaded</th>
</tr>";
while($row = mysql_fetch_array($result_display)){
$id = $row['id'];
$pic = $row['pic'];
$d = $row['date_posted'];
echo "<tr>
<td>$id</td>
<td>$pic</td>
<td>$d</td>
</tr>";
}
echo "</table>";
}
I got the error message from the sql statement 'Unknown column 'Pics' in 'field list'. But actually I want to insert the url of the image to the table, let say 'Pics/image001.jpg' then when I retrieved the result, it'll be what I want. Once again, the date posted is 0000-00-00 which is not the result I wanted.
Any help would be appreciated. Thanks