
Oct 6th, 2007, 15:49
|
 |
Blog Moderator 
|
|
Join Date: Dec 2006
Location: Norwich
Posts: 686
Thanks: 4
Thanked 2 Times in 2 Posts
|
|
|
[SOLVED] Uploading
How would i get it so a user could use the form to upload a image to dir: images. Using the same for to add it to the DB
Quote:
<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="Name" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Dis:</td>
<td><input type="text" name="Dis" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">By:</td>
<td><input type="text" name="By" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">ImageURL:</td>
<td><input type="text" name="ImageURL" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form2">
</form>
|
- PHP: Select all
<?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"] == "form2")) { $insertSQL = sprintf("INSERT INTO images (Name, Dis, `By`, ImageURL) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['Name'], "text"), GetSQLValueString($_POST['Dis'], "text"), GetSQLValueString($_POST['By'], "text"), GetSQLValueString($_POST['ImageURL'], "text"));
mysql_select_db($database_localhost, $localhost); $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
$insertGoTo = "/admin/image.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); }
mysql_select_db($database_localhost, $localhost); $query_Recordset1 = "SELECT ImageID, ImageURL, `By` FROM images"; $Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?>
|