I have an insert record form which inserts content into a title and content field of a table (as well as id). I would like to add an upload form which will
Upload a file into a folder called 'docs'
Add the file name into a filed called 'doc' in the above table
Here is my code, could someone please modify it to add the upload functionality?
Many thanks
<?php require_once('../Connectio
ns/hudsonw
alker_conn
.php'); ?>
<?php
function GetSQLValueString($theValu
e, $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_STR
ING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUE
RY_STRING'
]);
}
if ((isset($_POST["MM_insert"
])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO jobs (content, title) VALUES (%s, %s)",
GetSQLValueString($_POST['
content'],
"text"),
GetSQLValueString($_POST['
title'], "text"));
mysql_select_db($database_
hudsonwalk
er_conn, $hudsonwalker_conn);
$Result1 = mysql_query($insertSQL, $hudsonwalker_conn) or die(mysql_error());
$insertGoTo = "content.php";
if (isset($_SERVER['QUERY_STR
ING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml"
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Add a Vacancy</title>
<link href="hwadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td>
Insert job details
</td>
</tr>
<tr valign="baseline">
<td><input type="text" name="title" value="Title" size="32"></td>
</tr>
<tr valign="baseline">
<td><textarea name="content" cols="60" rows="50">Content</textare
a>
</td>
</tr>
<tr valign="baseline">
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>