Forums

PHP

This topic is locked

inserting uploaded image name into database?

Posted 23 Jan 2005 05:17:11
1
has voted
23 Jan 2005 05:17:11 Chase Chase posted:
Ok, ii found a php image upload script that im using for a image gallery im trying to do for my site. but for it to work the way i need to i have to have certain information submited into a mysql table at the same time, now, i could just make it so i type the name of the image, but i would rather not have to for when im uploading alot of images and then i make some careless spelling mistakes and have to go back and fix them.

so, i can upload the image ok, and i can upload data to the table, but i dont know what value i have to put in, so that the name of the pic is automaticly inserted into the mysql table. here is the code (im gonna just do a skipt through alot of it and left the parts i felt where relevant, and some of its surroundings.

<?php include("../db.php"; ?>
<?php
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO data (picture_name, creator, cat_id) VALUES (%s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['picture_name'], "text",
GetSQLValueString($HTTP_POST_VARS['creator'], "text",
GetSQLValueString($HTTP_POST_VARS['cat_id'], "text");

mysql_select_db($database_wtf, $wtf);
$Result1 = mysql_query($insertSQL, $wtf) or die(mysql_error());
}

mysql_select_db($database_wtf, $wtf);
$query_Recordset1 = "SELECT * FROM data ORDER BY iga DESC";
$Recordset1 = mysql_query($query_Recordset1, $wtf) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>
<?php
if(isset($_POST['Submit']))
$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];
if (isset($_FILES['image']['name']))

*form name="form1" method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
<p>
<*input name="creator" type="text" id="creator" value="creator">
<*/p>
<*p>
<*input name="cat_id" type="text" id="cat_id" value="2">
<*/p>
<*p>
<*input type="file" name="image">
<*/p>
<*p>
<*input type="Submit" name="Submit" value="Submit"> </p>
<*p>
<*input type="hidden" name="MM_insert" value="form1">
<*input name="picture_name" type="text" id="picture_name" value=" ">
<*/p>
*form*'; }?>

see, the part im having trouble with is teh ( input name="picture_name" .. .. ..value= ?? ) i dont know what to put for the value so that the name of the image im uploading is automaticly added in there.. any help

Reply to this topic