Anishgiri
11-10-2010, 09:50 AM
I am trying to write the image path to a database, but why is it the path name on the database is different from the path name on the folder where the actual image is stored? And why the path on the database does not concat the .jpg.
add_data.php
mysql_query("insert room set roomnumber='$room_number'");
if (is_uploaded_file($_FILES['photos']['tmp_name']))
{
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['photos']['tmp_name'],
"photos/bal/$newname");
mysql_query("update room SET image_link='photos/bal/$newname' WHERE roomnumber='" . $_POST['room_number'] . "' ")
or die(mysql_error());
}
html
<FORM NAME="myform" enctype="multipart/form-data" ACTION="add_data.php" METHOD="post">
<INPUT TYPE="text" NAME="room_number" VALUE="">
<input type="file" name="photos">
<input type="submit" name="submit">
</form>
add_data.php
mysql_query("insert room set roomnumber='$room_number'");
if (is_uploaded_file($_FILES['photos']['tmp_name']))
{
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['photos']['tmp_name'],
"photos/bal/$newname");
mysql_query("update room SET image_link='photos/bal/$newname' WHERE roomnumber='" . $_POST['room_number'] . "' ")
or die(mysql_error());
}
html
<FORM NAME="myform" enctype="multipart/form-data" ACTION="add_data.php" METHOD="post">
<INPUT TYPE="text" NAME="room_number" VALUE="">
<input type="file" name="photos">
<input type="submit" name="submit">
</form>