Forums
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>
<?php require_once('Connections/fishinglincs.php'); ?>
<?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));
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM name="form1" ENCTYPE="multipart/form-data" ACTION="<?php echo $editFormAction; ?>" METHOD="POST">
<p> Name of Water :
<input type="text" name="name">
<br>
<br>
County:
<input name="county" type="text" id="county">
<br>
<br>
Short Description:
<br>
<textarea name="description" cols="50" rows="5" id="description"></textarea>
<br>
<br>
Full Details (best bait etc.): <br>
<textarea name="details" cols="50" rows="5" id="details"></textarea>
<br>
<br>
Species:<br>
<textarea name="species" cols="50" rows="5" id="species"></textarea>
<br>
<br>
Bans: <br>
<textarea name="bans" cols="50" rows="5" id="bans"></textarea>
<br>
<br>
Tickets available:;<br>
<textarea name="Tickets" cols="50" rows="5" id="Tickets"></textarea>
<br>
<br>
Directions from nearest Town: <br>
<textarea name="direcions" cols="50" rows="5" id="direcions"></textarea>
<br>
<br>
Photo of the Pond
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="submit">
</p>
<input type="hidden" name="MM_insert" value="form1">
</FORM>
<?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>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($userfile_type=="image/gif" || ($userfile_type=="image/pjpeg") {
if (file_exists($path . $userfile_name)) { echo "The file already exists<br>\n"; exit; }
$res = copy($userfile, $path . $userfile_name);
if (!$res) {
echo "upload failed!<br>\n"; exit; }
else
echo "upload sucessful<br>\n";
echo "File Name: $userfile_name<br>\n";
echo "File Size: $userfile_size bytes<br>\n";
echo "File Type: $userfile_type<br>\n";
} else { echo "Wrong file type<br>\n"; exit; }
}
?>
</body>
</html>
regards andy<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<?php require_once('Connections/fishinglincs.php'); ?>
<?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));
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM name="form1" ENCTYPE="multipart/form-data" ACTION="<?php echo $editFormAction; ?>" METHOD="POST">
<p> Name of Water :
<input type="text" name="name">
<br>
<br>
County:
<input name="county" type="text" id="county">
<br>
<br>
Short Description:
<br>
<textarea name="description" cols="50" rows="5" id="description"></textarea>
<br>
<br>
Full Details (best bait etc.): <br>
<textarea name="details" cols="50" rows="5" id="details"></textarea>
<br>
<br>
Species:<br>
<textarea name="species" cols="50" rows="5" id="species"></textarea>
<br>
<br>
Bans: <br>
<textarea name="bans" cols="50" rows="5" id="bans"></textarea>
<br>
<br>
Tickets available:;<br>
<textarea name="Tickets" cols="50" rows="5" id="Tickets"></textarea>
<br>
<br>
Directions from nearest Town: <br>
<textarea name="direcions" cols="50" rows="5" id="direcions"></textarea>
<br>
<br>
Photo of the Pond
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="submit">
</p>
<input type="hidden" name="MM_insert" value="form1">
</FORM>
<?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>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($userfile_type=="image/gif" || ($userfile_type=="image/pjpeg") {
if (file_exists($path . $userfile_name)) { echo "The file already exists<br>\n"; exit; }
$res = copy($userfile, $path . $userfile_name);
if (!$res) {
echo "upload failed!<br>\n"; exit; }
else
echo "upload sucessful<br>\n";
echo "File Name: $userfile_name<br>\n";
echo "File Size: $userfile_size bytes<br>\n";
echo "File Type: $userfile_type<br>\n";
} else { echo "Wrong file type<br>\n"; exit; }
}
?>
</body>
</html>