Hi, all. I'm working on a script that will take information from a form (staff name, staff bio, and then the picture).
Now, to test things out, I had a upload script that worked great. I also had the form set up to input the user-defined name and bio into a database (but no picture).
I'm now trying to combine the two scripts so you can submit all three fields at the same time, and am having a rather difficult time of it.
Here is the code after several attempts at re-working (I have not put in the upload script yet, as I'm not sure where to place it.):
<?php require_once('../Connections/hcc.php'); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?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"] == "addstaff")) {
$insertSQL = sprintf("INSERT INTO cms_staff (staffname, staffbio, staffpic) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['staffname'], "text"),
GetSQLValueString($_POST['staffbio'], "text"),
GetSQLValueString($_POST['staffpic'], "text"));
mysql_select_db($database_hcc, $hcc);
$Result1 = mysql_query($insertSQL, $hcc) or die(mysql_error());
$insertGoTo = "success.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin_temp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>HCC Control Panel</title>
<!-- InstanceEndEditable -->
<link href="../style/admin_style.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>
<div id="wrapper">
<div id="header">
<p>Control Panel</p>
<p> </p>
</div>
<div id="navigation">
<ul id="mainav">
<li></li>
<li></li>
<li><a href="logout.php">logout</a></li>
<li id="front"><a href="../index.php" target="_blank">front</a></li>
</ul>
</div>
<div id="container"><!-- InstanceBeginEditable name="edit_content" -->
<p id="ptitle">Add Staff</p>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="addstaff" id="forminsert">
<table width="0" border="0" cellspacing="0" cellpadding="0" id="tblinsert">
<tr>
<td><label for="staffname">Staff Name:</label></td>
<td><input type="text" name="staffname" id="staffname" /></td>
</tr>
<tr>
<td><label for="staffbio">Staff Bio:</label></td>
<td><textarea name="staffbio" id="staffbio" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td><label for="staffpic">Staff Picture:</label></td>
<td><input type="file" name="staffpic" id="staffpic" /></td>
</tr>
<tr>
<td> </td>
<td><p>
<input type="submit" name="button" id="button" value="Submit" />
</p></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="addstaff" />
</form>
<p> </p>
<!-- InstanceEndEditable --></div>
<div id="footer"><p>© Web Designer Justin Bell</p></div>
</div>
</body>
<!-- InstanceEnd --></html>
Here is the upload script that has worked in the past:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 70000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("../images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../images/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
$insertGoTo = "success.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
?>
Sorry if some of the code is hard to understand, I used some of Dreamweaver's functions to help write it.