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.
Thanks.
Mightyhokie
Code:<?php require_once('../Connections/blog.php'); ?> <?php require_once('sessonCheck.php'); ?> <?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"; 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"] == "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)); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <link href="blog.css" rel="stylesheet" type="text/css"> </head> <body> <div class="wrapper"> <form action="<?php echo $editFormAction; ?>" method="POST" name="insertRecord" enctype="multipart/form-data"> <table width="200" border="1"> <tr> <td>Date:</td> <td><input name="date" type="text" size="10" maxlength="10"></td> </tr> <tr> <td>Title:</td> <td><input name="title" type="text" size="50" maxlength="100"></td> </tr> <tr> <td>Content:</td> <td><textarea name="content" cols="100" rows="10"></textarea></td> </tr> <tr> <td>Image:</td> <td><input type="file" name="photo" size="40"></td> </tr> <tr> <td colspan="2"><input name="submit" type="submit" value="Submit"></td> </tr> </table> <input type="hidden" name="MM_insert" value="insertRecord"> <input name="blogID" type="hidden" value="blogID"> </form> </div> <!--end wrapper--> </body> </html>


Reply With Quote
Bookmarks