Re: Upload file field not working as a form element

From: Date: Sun, 21 Mar 2004 11:46:22 +0000
Subject: Re: Upload file field not working as a form element
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-181076@lists.php.net to get a copy of this message
All I am trying to do is insert the file name, not the file. The file is being uploaded to the server in a specific location. All I need is the filename inserted into the database. I've gotten the upload part to work and everything I just can't get the file name inserted for God knows what reason. I removed the upload code and am simply trying to insert the filename and userid into the database. The userid goes in but I cannot get the file name inserted. Here is the form: <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1"> <input name="filename" type="file" id="filename"> <input name="userid" type="hidden" id="userid" value="<?php echo $row_rsUSER['id']; ?>"> <input type="submit" name="Submit2" value="Upload" disabled> <input type="hidden" name="MM_insert" value="form1"> </form> and here is the php code <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO photos (id, photo) VALUES (%s, %s)", GetSQLValueString($_POST['userid'], "int"), GetSQLValueString($_POST['userid2'], "text")); mysql_select_db($database_connSPARTY, $connSPARTY); $Result1 = mysql_query($insertSQL, $connSPARTY) or die(mysql_error()); $insertGoTo = "complete.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); }

« previous php.general (#181076) next »