[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

03/02/2008 at 07:11PM PST, ID: 23208383
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.7

Upload 4 files and place paths in MySQL fields...

Asked by cgustaf in MySQL Server

Tags: PHP, IE 6+, http://www.ibtpartners.org/ccl/announce/news/crnt/ccl_news.php?

The following script intends to upload 4 files and place the paths to each of thoses 4 files in MySQL

But, it only uploads 1 file, and it places the path to that one file into the fields intended for each of the 4 files.  The result is that the one uploaded image is displayed 4 times on the display page.

http://www.ibtpartners.org/ccl/announce/news/crnt/ccl_news.php?

I think I understand why this is happening, but I do not know how to fix it so that each of the 4 files is uploaded, and the paths to those 4 files are inserted into the path field (pic1, pic2, pic3, pic 4) for each respective file.

Grateful for advice that will fix this problem.

Here is the code:

<?php require_once('../../Connections/CCL_Prayer.php'); ?>
<?php
mysql_select_db($database_CCL_Prayer, $CCL_Prayer);
$query_Recordset1 = "SELECT * FROM ccl_news ";
$Recordset1 = mysql_query($query_Recordset1, $CCL_Prayer) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

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']);
}
?>
<?php

include ($_SERVER['DOCUMENT_ROOT']."/ccl/announce/news/upload/upload_class.php"); //classes is the map where the class file is stored (one above the root)

$max_size = 2400*2400; // the max. size for uploading
      
$my_upload = new file_upload;

$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/ccl/announce/news/upload/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".jpg", ".png", ".gif"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 100; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
            
if(isset($_POST['Submit'])) {
      $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
      $my_upload->the_file = $_FILES['upload']['name'];
      $my_upload->http_error = $_FILES['upload']['error'];
      $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
      $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
      $new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
      if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
            $full_path = $my_upload->upload_dir.$my_upload->file_copy;
            $info = $my_upload->get_uploaded_file_info($full_path);

            // Define text variables needed to create path for image retreival
            $img_src = "<img src=\"/ccl/announce/news/upload/";
            $hspace = "\" hspace=\"10\" vspace=\"5\" align=\"left\" border=1>";

        // Isolate the filename into a variable, then concatenate 3 variables
            // to create the needed path to retreive the image
        $path = ($full_path);
        $my_filename = basename($path);
        $my_path_string = ($img_src.$my_filename.$hspace);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  //$insertSQL = sprintf("INSERT INTO ccl_news (title, sec1_head, sec1_text, pic1) VALUES (%s, %s, %s, %s)",
  $insertSQL = sprintf("INSERT INTO ccl_news (title, sec1_head, sec1_text, pic1, sec2_head, sec2_text, pic2, sec3_head, sec3_text, pic3, sec4_head, sec4_text, pic4) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['sec1_head'], "text"),
                       GetSQLValueString($_POST['sec1_text'], "text"),
                       GetSQLValueString($my_path_string, "text"),
                                 //GetSQLValueString($_POST['pic1'], "text"),
                       GetSQLValueString($_POST['sec2_head'], "text"),
                       GetSQLValueString($_POST['sec2_text'], "text"),
                       GetSQLValueString($my_path_string, "text"),
                                 //GetSQLValueString($_POST['pic2'], "text"),
                       GetSQLValueString($_POST['sec3_head'], "text"),
                       GetSQLValueString($_POST['sec3_text'], "text"),
                       GetSQLValueString($my_path_string, "text"),
                                 //GetSQLValueString($_POST['pic3'], "text"),
                       GetSQLValueString($_POST['sec4_head'], "text"),
                       GetSQLValueString($_POST['sec4_text'], "text"),                      
                                 GetSQLValueString($my_path_string, "text"));
                                 //GetSQLValueString($_POST['pic4'], "text"));

  mysql_select_db($database_CCL_Prayer, $CCL_Prayer);
  $Result1 = mysql_query($insertSQL, $CCL_Prayer) or die(mysql_error());

  $insertGoTo = "crnt/ccl_news.php";

  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
}
  header(sprintf("Location: %s", $insertGoTo));
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
@import url("../../CCS_Styles/ccl_css.css");
body {
      background-color: #D7C997;
}
body,td,th {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 12px;
}
.style1 {
      font-size: 16px;
      font-weight: bold;
      color: #0000FF;
}
-->
</style></head>

<body>
<table width="855" align="center" class="thin_border">
  <tr>
    <td width="845" colspan="2"><img src="file:///E|/My%20Documents/websites/ccl/Ribbon/ribbon_new_080217.png" width="845" height="129" align="right"></td>
  </tr>
  <tr>
    <td height="28" colspan="2"><div align="center" class="style1">Enter Newsletter Items </div></td>
  </tr>
  <tr>
    <td colspan="2"><form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1">
      <table width="844">
        <tr>
          <td colspan="2">Main Title:
            <input name="title" type="text" id="title" value="COVENANT CLASS NEWS AND UPDATES FOR SUNDAY " size="80"></td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
        </tr>
        <tr>
          <td width="422" valign="top"><strong>Section 1 </strong></td>
          <td width="410">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"><div align="left">Heading:<br>
                <input name="sec1_head" type="text" id="sec1_head" size="65">
          </div></td>
          <td valign="top">Text:<br>
            <textarea name="sec1_text" cols="46" id="sec1_text"></textarea>
            </td>
        </tr>
        <tr>
          <td height="59" valign="top"><div align="left">
            Picture Upload: <br>
            <input name="upload" type="file" id="upload" size="52">
            <br>
          </div></td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td height="16" valign="top"><div align="left"><strong>Section 2</strong></div></td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top">Heading:<br>
            <input name="sec2_head" type="text" id="sec2_head" size="65"></td>
          <td valign="top">Text:<br>
            <textarea name="sec2_text" cols="46" id="sec2_text"></textarea></td>
        </tr>
        <tr>
          <td height="61" valign="top">Picture Upload: <br>
            <input name="upload2" type="file" id="upload2" size="52">
            <br></td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"><strong>Section 3 </strong></td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"><div align="left">Heading<br>
                  <input name="sec3_head" type="text" id="sec3_head" size="65">
          </div></td>
          <td valign="top">Text:<br>
            <textarea name="sec3_text" cols="46" id="sec3_text"></textarea>            </td>
        </tr>
        <tr>
          <td height="59" valign="top"><div align="left">
            Picture Upload: <br>
            <input name="upload3" type="file" id="upload3" size="52">
            <br>
          </div></td>
          <td valign="top">Text:<br>              </td>
        </tr>
        <tr>
          <td height="16" valign="top"><strong>Section 4 </strong></td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"><div align="left">
            Heading:            <br>
            <input name="sec4_head" type="text" id="sec4_head" size="65">
            <br>
          </div></td>
          <td valign="top">Text:<br>
            <textarea name="sec4_text" cols="46" id="sec4_text"></textarea></td>
        </tr>
        <tr>
          <td height="47" valign="top">Picture Upload:<br>
            <input name="upload4" type="file" id="upload4" size="52"> </td>
          <td valign="top">&nbsp;</td>
        </tr>
        <tr valign="bottom">
          <td height="33" colspan="2"><div align="center">
            <input type="submit" name="Submit" value="Submit">
          </div></td>
          </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form></td>
  </tr>
</table>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
[+][-]03/02/08 08:10 PM, ID: 21028973

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MySQL Server
Sign Up Now!
Solution Provided By: mstrelan
Participating Experts: 1
Solution Grade: B
 
 
[+][-]03/11/08 02:17 AM, ID: 21094042

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 03:18 PM, ID: 21100973

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 03:43 PM, ID: 21101216

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/08 04:49 PM, ID: 21101628

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 04:58 PM, ID: 21101685

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/08 06:32 PM, ID: 21102292

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 06:37 PM, ID: 21102303

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/11/08 07:28 PM, ID: 21102519

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 07:59 PM, ID: 21102662

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 08:00 PM, ID: 21102668

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 08:10 PM, ID: 21102706

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/11/08 08:36 PM, ID: 21102815

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_2_20070628