| Stephen Cox 2005-01-18, 12:17 pm |
| I don't get it. When using a File Field on a form and inserting records
I get an error about the File Field being NULL? I know I selected a
file. Anyway, here's the code:
<?php require_once('Connections/test.php'); ?>
<?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 != "") ? "'" . $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"] == "myform")) {
$insertSQL = sprintf("INSERT INTO temp (file_name) VALUES (%s)",
GetSQLValueString($_POST['filetouse'], "text"));
mysql_select_db($database_test, $test);
$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="POST"
enctype="multipart/form-data" name="myform" id="myform">
<label>Select File
<input name="filetouse" type="file" id="filetouse">
add
<input type="submit" name="Submit" value="Submit">
</label>
<input type="hidden" name="MM_insert" value="myform">
</form>
</body>
</html>
This is just an example. But a VERY basic form and it still doesn't
work. I'm using mysql and the table has one field in it called file_name
varchar(254) NOT NULL.
At first I thought it had something to do with the length of the field -
but no data is being passed? Any ideas? Oh and I have this problem on
OSX and Windows.
Thanks...
|