I've looked all over and have basically found the same code for this issue, but it doesn't work for me. I'm not a real programmer, more of a graphic artist who has had to learn stuff, so it is hard to figure this out.

I have a form. In the form there is an upload file code. I want to have the user click that, select the image he wants to put on the site (in a folder called 'pix') and have the name of the file written to my database (into a field called 'photo').

I simply can not figure out how to make the code I keep finding all over work for me. I rely on Dreamweaver for a lot of my PHP. Anyway, here is the entire page. How do I do this? I'm pulling my hair out.


<?php require_once('../Connections/blog.php'); ?>
<?php require_once('sessonCheck.php'); ?>

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "insertRecord")) {
  $insertSQL = sprintf("INSERT INTO main (blogID, title, content, photo, `date`) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['blogID'], "int"),
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['content'], "text"),
                       GetSQLValueString($_POST['photo'], "text"),
                       GetSQLValueString($_POST['date'], "text"));

  mysql_select_db($database_blog, $blog);
  $Result1 = mysql_query($insertSQL, $blog) or die(mysql_error());

  $insertGoTo = "blogList.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  header(sprintf("Location: %s", $insertGoTo));


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<link href="blog.css" rel="stylesheet" type="text/css">


<div class="wrapper">

<form action="<?php echo $editFormAction; ?>" method="POST" name="insertRecord" enctype="multipart/form-data">

    <table width="200" border="1">
        <td><input name="date" type="text" size="10" maxlength="10"></td>
        <td><input name="title" type="text" size="50" maxlength="100"></td>
        <td><textarea name="content" cols="100" rows="10"></textarea></td>
        <td><input type="file" name="photo" size="40"></td>
        <td colspan="2"><input name="submit" type="submit" value="Submit"></td>
    <input type="hidden" name="MM_insert" value="insertRecord">
    <input name="blogID" type="hidden" value="blogID">

</div> <!--end wrapper-->