Forums

PHP

This topic is locked

database update

Posted 29 Sep 2002 14:22:43
1
has voted
29 Sep 2002 14:22:43 Andrew Jackson-Parr posted:
my site is based on a php/mysql search engine, what I would like to do is allow users to add more information to the database and add an image (I can do both just not on the same form). i would also like to grab the name of the image and store it in a database and wrap tags around another field as it is stored.

Hope I explianed ok and that u can help

regards andy <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

p.s. Im not a very good coded so as idiot proof as possible tnx <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Replies

Replied 01 Oct 2002 21:29:31
01 Oct 2002 21:29:31 Andrew Jackson-Parr replied:
ok Ive figured updating the database and uploading the image from the same form all i need to do now is grab the name from the image uploaded below is my code, any suggestions:

regards andy<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>


&lt;?php require_once('Connections/fishinglincs.php'); ?&gt;
&lt;?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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO fishing (name, county, details, species, bans, contact, directions, description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['name'], "text",
GetSQLValueString($HTTP_POST_VARS['county'], "text",
GetSQLValueString($HTTP_POST_VARS['details'], "text",
GetSQLValueString($HTTP_POST_VARS['species'], "text",
GetSQLValueString($HTTP_POST_VARS['bans'], "text",
GetSQLValueString($HTTP_POST_VARS['Tickets'], "text",
GetSQLValueString($HTTP_POST_VARS['direcions'], "text",
GetSQLValueString($HTTP_POST_VARS['description'], "text");

mysql_select_db($database_fishinglincs, $fishinglincs);
$Result1 = mysql_query($insertSQL, $fishinglincs) or die(mysql_error());

$insertGoTo = "search.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;FORM name="form1" ENCTYPE="multipart/form-data" ACTION="&lt;?php echo $editFormAction; ?&gt;" METHOD="POST"&gt;
&lt;p&gt; Name of Water : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp;
&lt;input type="text" name="name"&gt;
&lt;br&gt;
&lt;br&gt;
County: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;input name="county" type="text" id="county"&gt;
&lt;br&gt;
&lt;br&gt;
Short Description: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;br&gt;
&lt;textarea name="description" cols="50" rows="5" id="description"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;br&gt;
Full Details (best bait etc.): &lt;br&gt;
&lt;textarea name="details" cols="50" rows="5" id="details"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;br&gt;
Species:&lt;br&gt;
&lt;textarea name="species" cols="50" rows="5" id="species"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;br&gt;
Bans: &lt;br&gt;
&lt;textarea name="bans" cols="50" rows="5" id="bans"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;br&gt;
Tickets available:;&lt;br&gt;
&lt;textarea name="Tickets" cols="50" rows="5" id="Tickets"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;br&gt;
Directions from nearest Town: &lt;br&gt;
&lt;textarea name="direcions" cols="50" rows="5" id="direcions"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;br&gt;
Photo of the Pond&nbsp;&nbsp;
&lt;INPUT NAME="userfile" TYPE="file"&gt;
&lt;INPUT TYPE="submit" VALUE="submit"&gt;
&lt;/p&gt;
&lt;input type="hidden" name="MM_insert" value="form1"&gt;
&lt;/FORM&gt;

&lt;?php

// Image file upload by Bloody
// www.bloodys.com/
// email:
// If you use this script, please put a link back to www.bloodys.com/

$path = "";
$max_size = 200000;

if (is_uploaded_file($userfile)) {

if ($userfile_size&gt;$max_size) { echo "The file is too big&lt;br&gt;\n"; exit; }

if (($userfile_type=="image/gif" || ($userfile_type=="image/pjpeg") {

if (file_exists($path . $userfile_name)) { echo "The file already exists&lt;br&gt;\n"; exit; }

$res = copy($userfile, $path . $userfile_name);
if (!$res) {
echo "upload failed!&lt;br&gt;\n"; exit; }
else
echo "upload sucessful&lt;br&gt;\n";

echo "File Name: $userfile_name&lt;br&gt;\n";
echo "File Size: $userfile_size bytes&lt;br&gt;\n";
echo "File Type: $userfile_type&lt;br&gt;\n";
} else { echo "Wrong file type&lt;br&gt;\n"; exit; }

}

?&gt;
&lt;/body&gt;
&lt;/html&gt;

Reply to this topic