39 Replies Latest reply: Feb 16, 2014 8:08 AM by Prince Mike RSS

    Save image path to MySQL and store file

    jaumeH Community Member

      Hi there,

      I have a form that saves data to a MySQL db. In this form there are four input type file to upload images.

      Everything is made with the Dreamweaver wizard.

       

      What I need to do is to store the file path into MySQL and the file into a folder of the website.

      I assume that I need to change in GetSQLValueString($_POST['variable'], "text"), but I don't know how to do it.

       

      Anyone can help???

      Thank you VERY mcuh

      Jaume

        • 1. Re: Save image path to MySQL and store file
          goldbecca Community Member

          Hi Jaume,

           

          I can't claim credit for this - I got it from here

           

          So want you want to do is upload an image, saving the image itself within your site and the image name in your database.

           

          I haven't figured a way to do this in Dreamweaver wizards, without amending the code, but it's quite straightforward.

           

          Assuming you have a form for people to upload an image, and a new folder within your 'images' folder named 'uploads'...

           

          Using the Dreamweaver server behaviours will have added loads of hidden code to the top of your page, so you need to use the 'code' view to see this (or 'split' if you'd prefer to see both code and design views).

           

          On your form page (mine's called add.php), within the code at the very top of your page which will begin with <?php

           

          and end with

          ?>

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

           

          Add in the following code:

           $target = "../images/uploads/";  //This is the directory where images will be saved//
           $target = $target . basename( $_FILES['image']['name']);   //change the image and name to whatever your database fields are called//
          
          
          
          

           

          Your Dreamweaver wizard will have created the $_POST details needed for each field.  You need to change the one related to your image to a $_FILES rather than $_POST - look for the line that says something like this (depending on your fields):

           

          if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
            $insertSQL = sprintf("INSERT INTO database_name (name, Product_No, image) VALUES (%s, %s, %s)",
                                 GetSQLValueString($_POST['Name'], "text"),
                                 GetSQLValueString($_POST['Product_No'], "text"),
                                 GetSQLValueString($_POST['image'], "text"));
          

          And change the last line to this:

           

          GetSQLValueString($_FILES['image']['name'], "text"));
          

           

          That tells the form to insert the file to a specified location, and to insert the image's name - as text - into the database.  Now you need to specifiy the location:

           

           

            //This code writes the photo to the server//

          if(move_uploaded_file($_FILES['image']['tmp_name'], $target))

          {

           

          //And confirms it has worked//

          echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";

          }

          else {

           

          //Gives error if not correct//

          echo "Sorry, there was a problem uploading your file.";

          }

           

           

          So your amended php will now look like this:

           

          $target = "../images/uploads/";  //This is the directory where images will be saved//

          $target = $target . basename( $_FILES['image']['name']);   //change the image and name to whatever your database fields are called//

           

           

          if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

            $insertSQL = sprintf("INSERT INTO database_name (name, Product_No, image) VALUES (%s, %s, %s)",

                                 GetSQLValueString($_POST['Name'], "text"),

                                 GetSQLValueString($_POST['Product_No'], "text"),

                                   GetSQLValueString($_FILES['image']['name'], "text"));

           


            //This code writes the photo to the server//

          if(move_uploaded_file($_FILES['image']['tmp_name'], $target))

          {

           

          //And confirms it has worked//

          echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";

          }

          else {

           

          //Gives error if not correct//

          echo "Sorry, there was a problem uploading your file.";

          }

           

          Now in your HTML within the form, your code should look something like this:

           

          <label for="image">Image</label>
                <input name="image" type="file" id="image" value="<?php echo $row_add['image']; ?>" />
              </p>
              <p>
                <input type="Submit" name="Add" id="add" value="Add" />
               
                <input type="hidden" name="MM_insert" value="form1" />
            </form>

           

          To display the uploaded images on your website, just put in the location and echo the image field, remembering your ALT tag:

           

          <img src="images/uploads/<?php echo $row_get['image']; ?>" alt="<?php echo $row_get['name']; ?>" /></a>
          

           

          Good luck!

          • 2. Re: Save image path to MySQL and store file
            jaumeH Community Member

            Becca, thank you very much!!!

            I have some problems though, maybe you can help me ;-)

            I don't know where to place the

            $target = "../images/uploads/";  //This is the directory where images will be saved// $target = $target . basename( $_FILES['image']['name']);   //change the image and name to whatever your database fields are called// 

            I think everything else I understand quite well.

            I copy the code here so maybe you can have al look to it.

            Thank you once again

            Jaume.

             

             

             

             

            <?php require_once('Connections/Conexion1.php'); ?>

            <?php require_once('Connections/Conexion1.php'); ?>

            <?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_update"])) && ($_POST["MM_update"] == "UpdateForm")) {

              $updateSQL = sprintf("UPDATE detailsmachines SET Hours=%s, StateCons=%s, Accesory1=%s, Accesory2=%s, Accesory3=%s, Image1=%s, Image2=%s, Image3=%s, Image4=%s WHERE ID=%s",

                                   GetSQLValueString($_POST['HoursEdit'], "int"),

                                   GetSQLValueString($_POST['State'], "text"),

                                   GetSQLValueString($_POST['Accesory1'], "text"),

                                   GetSQLValueString($_POST['Accesory2'], "text"),

                                   GetSQLValueString($_POST['Accesory3'], "text"),

                                   GetSQLValueString($_POST['Image1'], "text"),

                                   GetSQLValueString($_POST['Image2'], "text"),

                                   GetSQLValueString($_POST['Image3'], "text"),

                                   GetSQLValueString($_POST['Image4'], "text"),

                                   GetSQLValueString($_POST['id'], "int"));

             

             

              mysql_select_db($database_Conexion1, $Conexion1);

              $Result1 = mysql_query($updateSQL, $Conexion1) or die(mysql_error());

             

             

              $updateGoTo = "Message Pages/Thanks.html";

              if (isset($_SERVER['QUERY_STRING'])) {

                $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

                $updateGoTo .= $_SERVER['QUERY_STRING'];

              }

              header(sprintf("Location: %s", $updateGoTo));

            }

             

             

            $colname_DetailRS1 = "-1";

            if (isset($_GET['recordID'])) {

              $colname_DetailRS1 = $_GET['recordID'];

            }

            mysql_select_db($database_Conexion1, $Conexion1);

            $query_DetailRS1 = sprintf("SELECT * FROM detailsmachines WHERE ID = %s", GetSQLValueString($colname_DetailRS1, "int"));

            $DetailRS1 = mysql_query($query_DetailRS1, $Conexion1) or die(mysql_error());

            $row_DetailRS1 = mysql_fetch_assoc($DetailRS1);

            $totalRows_DetailRS1 = mysql_num_rows($DetailRS1);

            ?><!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">

            <head>

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

            <title>Untitled Document</title>

            </head>

             

             

            <body>

             

             

            <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="UpdateForm" id="UpdateForm">

              <p>

                <label for="id"></label>

                <input name="id" type="hidden" id="id" value="<?php echo $row_DetailRS1['ID']; ?>" />

              </p>

              <table border="1" align="center">

                <tr>

                  <td>Family</td>

                  <td><?php echo $row_DetailRS1['Family']; ?></td>

                </tr>

                <tr>

                  <td>Chasis</td>

                  <td><?php echo $row_DetailRS1['Chasis']; ?></td>

                </tr>

                <tr>

                  <td>Model</td>

                  <td><?php echo $row_DetailRS1['Model']; ?></td>

                </tr>

                <tr>

                  <td>Price</td>

                  <td><?php echo $row_DetailRS1['Price']; ?></td>

                </tr>

                <tr>

                  <td>Hours</td>

                  <td><label for="HoursEdit"></label>

                    <label for="HoursEdit2"></label>

                  <input name="HoursEdit" type="text" id="HoursEdit2" value="<?php echo $row_DetailRS1['Hours']; ?>" /></td>

                </tr>

                <tr>

                  <td>Warehouse</td>

                  <td><?php echo $row_DetailRS1['Warehouse']; ?></td>

                </tr>

                <tr>

                  <td>StateCons</td>

                  <td><label for="State"></label>

                  <input name="State" type="text" id="State" value="<?php echo $row_DetailRS1['StateCons']; ?>" /></td>

                </tr>

                <tr>

                  <td>Accesory1</td>

                  <td><label for="Accesory1"></label>

                  <input name="Accesory1" type="text" id="Accesory1" value="<?php echo $row_DetailRS1['Accesory1']; ?>" /></td>

                </tr>

                <tr>

                  <td>Accesory2</td>

                  <td><input name="Accesory2" type="text" id="Accesory2" value="<?php echo $row_DetailRS1['Accesory2']; ?>" /></td>

                </tr>

                <tr>

                  <td>Accesory3</td>

                  <td><input name="Accesory3" type="text" id="Accesory3" value="<?php echo $row_DetailRS1['Accesory3']; ?>" /></td>

                </tr>

                <tr>

                  <td>Accesory4</td>

                  <td><input name="Accesory4" type="text" id="Accesory4" value="<?php echo $row_DetailRS1['Accesory4']; ?>" /></td>

                </tr>

                <tr>

                  <td>Image1</td>

                  <td><label for="Image1"></label><input name="Image1" type="file" id="Image1" value="<?php $row_DetailRS1['Image1']->file_src_pathname; ?>"/>

                  </td>

                </tr>

                <tr>

                  <td>Image2</td>

                  <td><label for="Image2"></label>

                  <input name="Image2" type="file" id="Image2" value="<?php echo $row_DetailRS1['Image2']; ?>" /></td>

                </tr>

                <tr>

                  <td>Image3</td>

                  <td><label for="Image3"></label>

                  <input name="Image3" type="file" id="Image3" value="<?php echo $row_DetailRS1['Image3']; ?>" /></td>

                </tr>

                <tr>

                  <td>Image4</td>

                  <td><label for="Image4"></label>

                  <input name="Image4" type="file" id="Image4" value="<?php echo $row_DetailRS1['Image4']; ?>" /></td>

                </tr>

              </table>

              <p align="center">

                <input type="submit" name="Submit" id="Submit" value="Update" />

              </p>

              <input type="hidden" name="MM_update" value="UpdateForm" />

            </form>

            <p> </p>

            </body>

            </html><?php

            mysql_free_result($DetailRS1);

            ?>

            • 3. Re: Save image path to MySQL and store file
              goldbecca Community Member

              Hi Jaume,

               

              The $target bit on mine is inbetween the $editFormAction  and the if ((isst... To be honest I don't know that it matters where it goes, but it works there on mine!

               

              So that bit of code would look like this:

               

                $editFormAction = $_SERVER['PHP_SELF'];
               if (isset($_SERVER['QUERY_STRING'])) {
                $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
              }
              
              $target = "../images/uploads/";  //This is the directory where images will be saved//
               $target = $target . basename( $_FILES['image']['name']);  
              
              if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "UpdateForm")) {
              
              

               

              If it has worked, you'll end up with just the image's name (eg image.jpg) in your database field and the image file itself within your Dreamweaver site's images folder.

              • 4. Re: Save image path to MySQL and store file
                Lon Winters Community Member

                Just for something to think about, I've always been divided/uncertain if saving the path with the filename is the best way to go. If anything, I think I would at least store the filename in a separate column. The reason being that often, you don't always know where the page will be that will eventually link to the file and document relative links then may not work.

                 

                The path can be added to the image source string at any time - either as a static or dynamic value.

                • 5. Re: Save image path to MySQL and store file
                  MurraySummers CommunityMVP

                  I would never store the pathname like that.  Just add it in the static HTML on the page.

                  • 6. Re: Save image path to MySQL and store file
                    jaumeH Community Member

                    Thank you Lon and Murray for your comments.

                    I'd like to know, though, how would you do it.

                     

                    My website is a "used machine info" site. I would like to show the machines we have for sale with 4 pics and a table with the specs of each one.

                    It is generated dynamically, so when I pick one it shows the details.

                    There is also an admin panel where the staff can upload the pics.

                     

                    I thought it would be hard to store the pic in the MySQL so I decided to upload the file to ther server and save the path in the db.

                    What do you think???

                    Is there any other way to do it??

                    how about a flickr API?

                     

                    Once again thankl you VERY much for all your help

                    Jaume

                    • 7. Re: Save image path to MySQL and store file
                      MurraySummers CommunityMVP

                      I thought it would be hard to store the pic in the MySQL so I decided to upload the file to ther server and save the path in the db.

                      What do you think???

                       

                      I think this is the right way to do it, except just save the image NAME - put the path in the static HTML, e.g.,

                       

                      <img src="path_to_the_image_location/<?php echo $image_file_name; ?>"

                       

                      That way if you ever change the image location, you only have to change that one line not every record in the database.

                      • 8. Re: Save image path to MySQL and store file
                        Lon Winters Community Member

                        And, to go fully not state the obvious, the image file name value will come from a recordset in most situations.

                         

                        One way to do it if you're working with a detail page for example, is to create the recordset as you normally would for a detail page, using the unique recordID that's passed from the master page. Insert an image placeholder and for the source, click the lightning bolt icon for dynamic data and select the image file name column from the recordset. Then add the path in manually so it ends up like what Murray posted.

                         

                        The image placeholder will also add height and width attributes that default to 32x32. So if all the images are the same size, change the attributes accordingly. If they're not the same size, and here's something I should know - will removing those attributes altogether just display the image in it's native dimensions?

                        • 9. Re: Save image path to MySQL and store file
                          MurraySummers CommunityMVP

                          If they're not the same size, and here's something I should know - will removing those attributes altogether just display the image in it's native dimensions?

                           

                          Yes.  If the various images are going to have different dimensions, then you will either have to also store the dimensions in the database, or just remove them from the image tag altogether as you have suggested. You can also use PHP to get the image's dimensions, but that seems like a long walk around the park for this purpose.

                          • 10. Re: Save image path to MySQL and store file
                            Lon Winters Community Member

                            Then comes the issue of what the dimensions of the images actually are. Going back to the top of the thread, they are user uploaded images, so that means they can come in just about any size and resolution. So the uploading process should also include resizing to a maximum width and/or height.

                            • 11. Re: Save image path to MySQL and store file
                              MurraySummers CommunityMVP

                              Certainly - always.

                              • 12. Re: Save image path to MySQL and store file
                                jaumeH Community Member

                                Gentelmen, thanks a lot again!!

                                I haven't realized about what Lon says. And it is ABSOLUTELY true.

                                I will need to resize the big images to a certain size.

                                Can this be done with dreamweaver????

                                Any ideas?

                                Thanks

                                Jaume

                                • 13. Re: Save image path to MySQL and store file
                                  MurraySummers CommunityMVP

                                  Can this be done with dreamweaver????

                                   

                                  That is not the question.  You should ask "Can this be done with PHP", and the answer is yes, sure.  Google "PHP image resize" - you'll find lots....

                                  • 15. Re: Save image path to MySQL and store file
                                    jaumeH Community Member

                                    VERY nice but expensive :-(

                                    Thank you VERY much anyway!!!

                                    • 16. Re: Save image path to MySQL and store file
                                      Felix1 Community Member

                                      Yes if this is the only time you are going to do that I'm agreeing with you, it is very expensive. But for a regular webdesigner I don't think it is worth to spend days to find a solution on the internet expecially when you have to face situations like that many times and any time with different details, if it is true that "time is money" it would be much more expensive to spend weeks or months to find a solution that you could have at your finger tips. After all regular webdesigners don't love coding.

                                       

                                      Of course I don't know your state so, in one way such a solution may be expensive on the other way it is not, but that was just a suggestion.

                                       

                                      Thanks to you

                                      • 17. Re: Save image path to MySQL and store file
                                        jaumeH Community Member

                                        You are right plus the library is AWESOME!!!!!!!

                                        Shame I do this just for once.

                                        Thanks for the tip ;-)

                                        Jaume

                                        • 18. Re: Save image path to MySQL and store file
                                          pablodelriob Community Member

                                          Hi, sorry for my english, my english is very bad

                                           

                                          My code, as the code is exposed:


                                          // Variables

                                          # Definiendo la carpeta #

                                          $target = "productos/";

                                           

                                          # Definiendo la variable IMAGEN #

                                          $mat_img = $_FILES['mat_img']['name'];

                                           

                                          # Haciendo que funcione! #

                                          $target = $target . basename( $_FILES['mat_img']['name']);

                                          // Insert dreamweaver

                                          // change $_FILES['mat_img']['name'], "text"),

                                          GetSQLValueString($_FILES['mat_img']['name'], "text"),

                                           

                                          // And finish

                                           

                                          if(move_uploaded_file($_FILES['mat_img']['tmp_name'], $target))

                                          {

                                           

                                          mysql_select_db($database_adis, $adis);

                                           

                                          # Ejectutar la consulta para insertar! #

                                            $Result1 = mysql_query($insertSQL, $adis) or die(mysql_error());

                                           

                                            $insertGoTo = "bien.php";

                                            if (isset($_SERVER['QUERY_STRING'])) {

                                              $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

                                              $insertGoTo .= $_SERVER['QUERY_STRING'];

                                            }

                                            header(sprintf("Location: %s", $insertGoTo));

                                          # Si todo salio exito!, mostar mensaje! #

                                          echo "The file ". basename( $_FILES['mat_img']['name']). " has been uploaded, and your information has been added to the directory";

                                          }

                                          else {

                                           

                                          # Y si no, mostrar un mensaje! #

                                          echo "Sorry, there was a problem uploading your file.";

                                           

                                          }


                                          // Code Complete

                                           

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

                                          }

                                           

                                           

                                          # Definiendo la carpeta #

                                          $target = "productos/";

                                           

                                          # Definiendo la variable IMAGEN #

                                          $mat_img = $_FILES['mat_img']['name'];

                                           

                                          # Haciendo que funcione! #

                                          $target = $target . basename( $_FILES['mat_img']['name']);

                                           

                                           

                                          if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {

                                            $insertSQL = sprintf("INSERT INTO material (mat_tipo, mat_fecha, mat_numero, mat_codigo, mat_deta1, mat_deta2, mat_img, idcolaborador, idciudad, idlocal, direccion, hora, costo, fechapanel, idestado) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                                                                 GetSQLValueString($_POST['mat_tipo'], "int"),

                                                                 GetSQLValueString($_POST['mat_fecha'], "text"),

                                                                 GetSQLValueString($_POST['mat_numero'], "text"),

                                                                 GetSQLValueString($_POST['mat_codigo'], "text"),

                                                                 GetSQLValueString($_POST['mat_deta1'], "text"),

                                                                 GetSQLValueString($_POST['mat_deta2'], "text"),

                                                                 GetSQLValueString($_FILES['mat_img']['name'], "text"),

                                                                 GetSQLValueString($_POST['idcolaborador'], "int"),

                                                                 GetSQLValueString($_POST['idciudad'], "int"),

                                                                 GetSQLValueString($_POST['idlocal'], "int"),

                                                                 GetSQLValueString($_POST['direccion'], "text"),

                                                                 GetSQLValueString($_POST['hora'], "text"),

                                                                 GetSQLValueString($_POST['costo'], "text"),

                                                                 GetSQLValueString($_POST['fechapanel'], "text"),

                                                                 GetSQLValueString($_POST['idestado'], "int"));

                                           

                                           

                                                                

                                          # Si todo salio OK, copiar la imagen a la carpeta definida #

                                           

                                          if(move_uploaded_file($_FILES['mat_img']['tmp_name'], $target))

                                          {

                                             

                                          mysql_select_db($database_adis, $adis);

                                           

                                          # Ejectutar la consulta para insertar! #

                                            $Result1 = mysql_query($insertSQL, $adis) or die(mysql_error());

                                           

                                            $insertGoTo = "bien.php";

                                            if (isset($_SERVER['QUERY_STRING'])) {

                                              $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

                                              $insertGoTo .= $_SERVER['QUERY_STRING'];

                                            }

                                            header(sprintf("Location: %s", $insertGoTo));

                                          # Si todo salio exito!, mostar mensaje! #

                                          echo "The file ". basename( $_FILES['mat_img']['name']). " has been uploaded, and your information has been added to the directory";

                                          }

                                          else {

                                           

                                          # Y si no, mostrar un mensaje! #

                                          echo "Sorry, there was a problem uploading your file.";

                                           

                                          }

                                           

                                          }

                                           

                                          mysql_select_db($database_adis, $adis);

                                          $query_disertante = "SELECT * FROM colaboradores";

                                          $disertante = mysql_query($query_disertante, $adis) or die(mysql_error());

                                          $row_disertante = mysql_fetch_assoc($disertante);

                                          $totalRows_disertante = mysql_num_rows($disertante);

                                           

                                          mysql_select_db($database_adis, $adis);

                                          $query_ciudad = "SELECT * FROM ciudades";

                                          $ciudad = mysql_query($query_ciudad, $adis) or die(mysql_error());

                                          $row_ciudad = mysql_fetch_assoc($ciudad);

                                          $totalRows_ciudad = mysql_num_rows($ciudad);

                                           

                                          mysql_select_db($database_adis, $adis);

                                          $query_locales = "SELECT * FROM locales";

                                          $locales = mysql_query($query_locales, $adis) or die(mysql_error());

                                          $row_locales = mysql_fetch_assoc($locales);

                                          $totalRows_locales = mysql_num_rows($locales);

                                          ?>

                                          Hope you are useful!

                                          • 19. Re: Save image path to MySQL and store file
                                            Prince Mike Community Member

                                            Hello Goldbecca and ALL:

                                             

                                            Please I need your assistance.

                                             

                                            I followsed the procedues head to toll but my images are not uploading. Please could you go through and kindly advice. I have spent all night working on this but its not uploading to the upload folder inside the Image folder.

                                             

                                            Here is the fiest part ofd the code on the same page

                                             

                                            $editFormAction = $_SERVER['PHP_SELF'];

                                            if (isset($_SERVER['QUERY_STRING'])) {

                                              $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

                                            }

                                             

                                             

                                            $target = "images/uploads/";  //This is the directory where images will be saved//

                                                      $target = $target . basename( $_FILES['Projimg1']['name']);

                                                      $target = $target . basename( $_FILES['Projimg2']['name']);

                                                      $target = $target . basename( $_FILES['Projimg3']['name']); 

                                             

                                             

                                            if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "submitpage")) {

                                              $insertSQL = sprintf("INSERT INTO tbl_projects (projcode, projname, projdesc, projdateentered, projcommunity, projlga, projstate, projcost, projtype, projbaselinedata, Projexpoutcome, adultmen, adultfem, totalchildren, totalben, projteamlead, projdepteamlead, projofficer, projliasonofficer, projmeeting1, projmeeting2, projmeeting3, projmousigndate, projstartdate, projenddate, Projdoc1, Projdoc2, Projdoc3, Projimg1, Projimg2, Projimg3) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                                                                   GetSQLValueString($_POST['projcode'], "text"),

                                                                   GetSQLValueString($_POST['projname'], "text"),

                                                                   GetSQLValueString($_POST['projdesc'], "text"),

                                                                   GetSQLValueString($_POST['projdateentered'], "date"),

                                                                   GetSQLValueString($_POST['projcommunity'], "text"),

                                                                   GetSQLValueString($_POST['projlga'], "text"),

                                                                   GetSQLValueString($_POST['projstate'], "text"),

                                                                   GetSQLValueString($_POST['projcost'], "double"),

                                                                   GetSQLValueString($_POST['projtype'], "text"),

                                                                   GetSQLValueString($_POST['projbaselinedata'], "text"),

                                                                   GetSQLValueString($_POST['Projexpoutcome'], "text"),

                                                                   GetSQLValueString($_POST['adultmen'], "int"),

                                                                   GetSQLValueString($_POST['adultfem'], "int"),

                                                                   GetSQLValueString($_POST['totalchildren'], "int"),

                                                                   GetSQLValueString($_POST['totalben'], "int"),

                                                                   GetSQLValueString($_POST['projteamlead'], "text"),

                                                                   GetSQLValueString($_POST['projdepteamlead'], "text"),

                                                                   GetSQLValueString($_POST['projofficer'], "text"),

                                                                   GetSQLValueString($_POST['projliasonofficer'], "text"),

                                                                   GetSQLValueString($_POST['projmeeting1'], "date"),

                                                                   GetSQLValueString($_POST['projmeeting2'], "date"),

                                                                   GetSQLValueString($_POST['projmeeting3'], "date"),

                                                                   GetSQLValueString($_POST['projmousigndate'], "date"),

                                                                   GetSQLValueString($_POST['projstartdate'], "date"),

                                                                   GetSQLValueString($_POST['projenddate'], "date"),

                                                                   GetSQLValueString($_POST['Projdoc1'], "text"),

                                                                   GetSQLValueString($_POST['Projdoc2'], "text"),

                                                                   GetSQLValueString($_POST['Projdoc3'], "text"),

                                                                   GetSQLValueString($_FILES['Projimg1']['name'], "text"),

                                                                   GetSQLValueString($_FILES['Projimg2']['name'], "text"),

                                                                   GetSQLValueString($_FILES['Projimg3']['name'], "text"));

                                             

                                             

                                              mysql_select_db($database_ProjMonEva, $ProjMonEva);

                                              $Result1 = mysql_query($insertSQL, $ProjMonEva) or die(mysql_error());

                                             

                                             

                                              $insertGoTo = "projects.php";

                                              if (isset($_SERVER['QUERY_STRING'])) {

                                                $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

                                                $insertGoTo .= $_SERVER['QUERY_STRING'];

                                              }

                                              header(sprintf("Location: %s", $insertGoTo));

                                            }

                                             

                                             

                                            //This code writes the photo to the server//

                                            if(move_uploaded_file($_FILES['Projimg1']['tmp_name'], $target))

                                            {

                                             

                                             

                                            //And confirms it has worked//

                                            echo "The file ". basename( $_FILES['Projimg1']['name']). " has been uploaded, and your information has been added to the directory";

                                            }

                                            else {

                                             

                                            //Gives error if not correct//

                                            echo "Sorry, there was a problem uploading your file.";

                                            }

                                             

                                             

                                            //This code writes the photo to the server//

                                            if(move_uploaded_file($_FILES['Projimg2']['tmp_name'], $target))

                                            {

                                             

                                             

                                            //And confirms it has worked//

                                            echo "The file ". basename( $_FILES['Projimg2']['name']). " has been uploaded, and your information has been added to the directory";

                                            }

                                            else {

                                             

                                            //Gives error if not correct//

                                            echo "Sorry, there was a problem uploading your file.";

                                            }

                                             

                                            //This code writes the photo to the server//

                                            if(move_uploaded_file($_FILES['Projimg3']['tmp_name'], $target))

                                            {

                                             

                                             

                                            //And confirms it has worked//

                                            echo "The file ". basename( $_FILES['Projimg3']['name']). " has been uploaded, and your information has been added to the directory";

                                            }

                                            else {

                                             

                                            //Gives error if not correct//

                                            echo "Sorry, there was a problem uploading your file.";

                                            }

                                             

                                            and the second part on the same page

                                             

                                            <fieldset>

                                                  <legend>Review & Submit</legend>

                                                  <form id="submitpage" name="submitpage" method="POST" action="<?php echo $editFormAction; ?>">

                                                    <div align="center">

                                                      <table width="500" border="0" cellspacing="0" cellpadding="0">

                                                        <tr>

                                                          <td colspan="2"><strong>Core  Project Details</strong></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td width="235"><p>Project Code:

                                                            <input name="projcode" type="text" id="projcode" value="<?php echo $_POST['projcode']; ?>" />

                                                          </p></td>

                                                          <td width="265"><p>

                                                            <label for="projcode"></label>

                                                            Project Name:

                                                            <input name="projname" type="text" id="projname" value="<?php echo $_POST['projname']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td colspan="2"><p>Project Description:<span id="description"></span></p>                <p>

                                                              <label for="projdesc"></label>

                                                              <textarea name="projdesc" id="projdesc" cols="60" rows="8"><?php echo $_POST['projdesc']; ?></textarea>

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project Year:

                                                            <input name="projdateentered" type="text" id="projdateentered" value="<?php echo $_POST['projdateentered']; ?>" />

                                                          </p></td>

                                                          <td><p>Project LGA:

                                                            <input name="projlga" type="text" id="projlga" value="<?php echo $_POST['projlga']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project Community:

                                                            <input name="projcommunity" type="text" id="projcommunity" value="<?php echo $_POST['projcommunity']; ?>" />

                                                          </p></td>

                                                          <td><p>Project State:

                                                            <input name="projstate" type="text" id="projstate" value="<?php echo $_POST['projstate']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td colspan="2"><p>Project Baseline Data:</p>                <p>

                                                              <textarea name="projbaselinedata" id="projbaselinedata" cols="60" rows="8"><?php echo $_POST['projbaselinedata']; ?></textarea>

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td colspan="2"><p>Expected Outcome Of Project:</p>                <p>

                                                              <textarea name="Projexpoutcome" id="Projexpoutcome" cols="60" rows="8"><?php echo $_POST['Projexpoutcome']; ?></textarea>

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project Cost:

                                                            <input name="projcost" type="text" id="projcost" value="<?php echo $_POST['projcost']; ?>" />

                                                          </p></td>

                                                          <td><p>

                                                            Project Type:

                                                              <input name="projtype" type="text" id="projtype" value="<?php echo $_POST['projtype']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td colspan="2"><strong>Beneficiaries</strong></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Adult Men Beneficiaries:

                                                            <input name="adultmen" type="text" id="adultmen" value="<?php echo $_POST['adultmen']; ?>" />

                                                          </p></td>

                                                          <td><p>Adult Female Beneficiaries:

                                                            <input name="adultfem" type="text" id="adultfem" value="<?php echo $_POST['adultfem']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Adult Children Beneficiaries:

                                                            <input name="totalchildren" type="text" id="totalchildren" value="<?php echo $_POST['totalchildren']; ?>" />

                                                          </p></td>

                                                          <td><p>Total Beneficiaries:

                                                            <input name="totalben" type="text" id="totalben" value="<?php echo $_POST['totalben']; ?>" readonly="readonly" />

                                                          </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td colspan="2"><strong>Project Team</strong></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project Team Leader:

                                                            <input name="projteamlead" type="text" id="projteamlead" value="<?php echo $_POST['projteamlead']; ?>" />

                                                          </p></td>

                                                          <td><p>Deputy Team Leader:

                                                            <input name="projdepteamlead" type="text" id="projdepteamlead" value="<?php echo $_POST['projdepteamlead']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project Officer:

                                                            <input name="projofficer" type="text" id="projofficer" value="<?php echo $_POST['projofficer']; ?>" />

                                                          </p></td>

                                                          <td><p>Liason Officer:

                                                            <input name="projliasonofficer" type="text" id="projliasonofficer" value="<?php echo $_POST['projliasonofficer']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td colspan="2"><strong>Meeting Dates</strong></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>First Project Meeting Date:

                                                            <input name="projmeeting1" type="text" id="projmeeting1" value="<?php echo $_POST['projmeeting1']; ?>" />

                                                          </p></td>

                                                          <td><p>Third Project Meeting Date:

                                                            <input name="projmeeting3" type="text" id="projmeeting3" value="<?php echo $_POST['projmeeting3']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Second Project Meeting

                                                           

                                                          Date:

                                                              <input name="projmeeting2" type="text" id="projmeeting2" value="<?php echo $_POST['projmeeting2']; ?>" />

                                                          </p></td>

                                                          <td><p> </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td colspan="2"><strong>Other Dates</strong></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project Start Date:

                                                              <label for="projstartdate"></label>

                                                              <input name="projstartdate" type="text" id="projstartdate" value="<?php echo $_POST['projstartdate']; ?>" />

                                                          </p></td>

                                                          <td><p>MoU Signing Date:

                                                            <input name="projmousigndate" type="text" id="projmousigndate" value="<?php echo $_POST['projmousigndate']; ?>" />

                                                          </p></td>

                                                        </tr>

                                                        <tr id="rowlines">

                                                          <td><p>Project End Date:

                                                              <label for="projstartdate"></label>

                                                              <input name="projenddate" type="text" id="projenddate" value="<?php echo $_POST['projenddate']; ?>" />

                                                          </p></td>

                                                          <td><p> </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td> </td>

                                                          <td> </td>

                                                        </tr>

                                                        <tr id="moredetails">

                                                          <td colspan="2" id="moredetails"><strong>Upload Initial Project Documents/Pictures</strong></td>

                                                        </tr>

                                                        <tr>

                                                          <td id="formcells"><p>Document/Picture One:

                                                            <label for="Projdoc1"></label>

                                                            <input type="file" name="Projdoc1" id="Projdoc1" />

                                                          </p></td>

                                                          <td id="formcells"><p>Document/Picture Four:

                                                            <label for="Projimg1"></label>

                                                            <input type="file" name="Projimg1" id="Projimg1" />

                                                          </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td id="formcells"><p>Document/Picture Two:

                                                            <label for="Projdoc2"></label>

                                                            <input type="file" name="Projdoc2" id="Projdoc2" />

                                                          </p></td>

                                                          <td id="formcells"><p>Document/Picture Five:

                                                            <label for="Projimg2"></label>

                                                            <input type="file" name="Projimg2" id="Projimg2" />

                                                          </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td id="formcells"><p>Document/Picture Three:

                                                            <label for="Projdoc3"></label>

                                                            <input type="file" name="Projdoc3" id="Projdoc3" />

                                                          </p></td>

                                                          <td id="formcells"><p>Document/Picture Six:

                                                            <label for="Projimg3"></label>

                                                            <input type="file" name="Projimg3" id="Projimg3" />

                                                          </p></td>

                                                        </tr>

                                                        <tr>

                                                          <td colspan="2"> </td>

                                                        </tr>

                                                      </table>

                                                      <p>

                                                        <input type="submit" name="btn_submit" id="btn_submit" value="Save &amp; Submit" />

                                                      </p>

                                                    </div>

                                                    <!-- end .content -->

                                                    <input type="hidden" name="MM_insert" value="submitpage" /> 

                                                  </form>

                                                </fieldset>

                                            • 20. Re: Save image path to MySQL and store file
                                              bregent CommunityMVP

                                              In the future, you should probably not reply to a 3 year old post and expect to get many replies - especially when that post was marked as 'Resolved'.

                                               

                                              The first thing I noticed is that you have not set the correct enctype for file uploads.

                                              You need to have the enctype="multipart/form-data" in your form tag. I haven't really looked further, there may be other problems.

                                              • 21. Re: Save image path to MySQL and store file
                                                goldbecca Community Member

                                                1. Agreed. Amend the line:      

                                                               <form id="submitpage" name="submitpage" method="POST" action="<?php echo $editFormAction; ?>">

                                                to:

                                                                <form id="submitpage" name="submitpage" method="POST" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>">

                                                 

                                                2. Also, is this file in the same directory as your images folder? If not, this line won't work:

                                                               $target = "images/uploads/";  //This is the directory where images will be saved//

                                                It needs to be relative to the path, or make it absolute (http://www.yoursite.com/images/uploads/)

                                                 

                                                3. I also think, and this was written so long ago that I can't really remember, the three lines relating to confirmation eg:

                                                 

                                                          //And confirms it has worked//

                                                          echo "The file ". basename( $_FILES['Projimg1']['name']). " has been uploaded, and your information has been added to the directory";

                                                 

                                                Should say:

                                                 

                                                           //Tells you if its all ok

                                                           echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";

                                                 

                                                Ie, I don't think you need the image field here, just the word 'uploadedfile'. Though I can't find where this would relate to so I could be wrong

                                                • 22. Re: Save image path to MySQL and store file
                                                  Prince Mike Community Member

                                                  Hi Goldbecca,

                                                   

                                                  Thank you for your response.

                                                   

                                                  I followed your corrections but the upload still did not go through. Just to be sure I did all things well, on this line

                                                   

                                                                 $target = "images/uploads/";  //This is the directory where images will be saved//

                                                  It needs to be relative to the path, or make it absolute (http://www.yoursite.com/images/uploads/)

                                                   

                                                   

                                                  am I supposed to put the image path is double quote like this "http://localhost/projmoneva/images/uploads/" or should I just live it like this http://localhost/projmoneva/images/uploads/?

                                                   

                                                  Thank you

                                                   

                                                  Mik

                                                  • 23. Re: Save image path to MySQL and store file
                                                    bregent CommunityMVP

                                                    I really don't know much about php, but I'd be surprised if a file based function like move_uploaded_file() works with an absolute url. Really, I think you are much better off referencing the document root:

                                                     

                                                    target_path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/" . basename( $_FILES['Projimg1']['name']).

                                                     

                                                    >am I supposed to put the image path is double quote

                                                     

                                                    Of course - you are populating a variable with a string.

                                                     

                                                    What error message if any are you getting? Do you have error reporting enabled?

                                                    • 24. Re: Save image path to MySQL and store file
                                                      Prince Mike Community Member

                                                      I am also having errors on lines

                                                       

                                                      $target = $target . basename( $_FILES['Projimg1']['name']);

                                                      $target = $target . basename( $_FILES['Projimg2']['name']);

                                                      $target = $target . basename( $_FILES['Projimg3']['name']); 

                                                       

                                                      and this ones aswell

                                                       

                                                      if(move_uploaded_file($_FILES['Projimg1']['tmp_name'], $target))

                                                      if(move_uploaded_file($_FILES['Projimg2']['tmp_name'], $target))

                                                      if(move_uploaded_file($_FILES['Projimg3']['tmp_name'], $target))

                                                       

                                                      See image below

                                                      http://www.netdataflow.com/rbme/images/upload.gif

                                                      • 25. Re: Save image path to MySQL and store file
                                                        bregent CommunityMVP

                                                        And you're sure you added the enctype? Can we see your entire page again?

                                                        • 26. Re: Save image path to MySQL and store file
                                                          Prince Mike Community Member

                                                          Ok Here it is below. The online development version is here http://netdataflow.com/rbme/addprojectreview.php

                                                           

                                                          <fieldset>

                                                                <legend>Review & Submit</legend>

                                                                <form id="submitpage" name="submitpage" method="POST" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>">

                                                                  <div align="center">

                                                                    <table width="500" border="0" cellspacing="0" cellpadding="0">

                                                                      <tr>

                                                                        <td colspan="2"><strong>Core  Project Details</strong></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td width="235"><p>Project Code:

                                                                          <input name="projcode" type="text" id="projcode" value="<?php echo $_POST['projcode']; ?>" />

                                                                        </p></td>

                                                                        <td width="265"><p>

                                                                          <label for="projcode"></label>

                                                                          Project Name:

                                                                          <input name="projname" type="text" id="projname" value="<?php echo $_POST['projname']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td colspan="2"><p>Project Description:<span id="description"></span></p>                <p>

                                                                            <label for="projdesc"></label>

                                                                            <textarea name="projdesc" id="projdesc" cols="60" rows="8"><?php echo $_POST['projdesc']; ?></textarea>

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project Year:

                                                                          <input name="projdateentered" type="text" id="projdateentered" value="<?php echo $_POST['projdateentered']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Project LGA:

                                                                          <input name="projlga" type="text" id="projlga" value="<?php echo $_POST['projlga']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project Community:

                                                                          <input name="projcommunity" type="text" id="projcommunity" value="<?php echo $_POST['projcommunity']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Project State:

                                                                          <input name="projstate" type="text" id="projstate" value="<?php echo $_POST['projstate']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td colspan="2"><p>Project Baseline Data:</p>                <p>

                                                                            <textarea name="projbaselinedata" id="projbaselinedata" cols="60" rows="8"><?php echo $_POST['projbaselinedata']; ?></textarea>

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td colspan="2"><p>Expected Outcome Of Project:</p>                <p>

                                                                            <textarea name="Projexpoutcome" id="Projexpoutcome" cols="60" rows="8"><?php echo $_POST['Projexpoutcome']; ?></textarea>

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project Cost:

                                                                          <input name="projcost" type="text" id="projcost" value="<?php echo $_POST['projcost']; ?>" />

                                                                        </p></td>

                                                                        <td><p>

                                                                          Project Type:

                                                                            <input name="projtype" type="text" id="projtype" value="<?php echo $_POST['projtype']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td colspan="2"><strong>Beneficiaries</strong></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Adult Men Beneficiaries:

                                                                          <input name="adultmen" type="text" id="adultmen" value="<?php echo $_POST['adultmen']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Adult Female Beneficiaries:

                                                                          <input name="adultfem" type="text" id="adultfem" value="<?php echo $_POST['adultfem']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Adult Children Beneficiaries:

                                                                          <input name="totalchildren" type="text" id="totalchildren" value="<?php echo $_POST['totalchildren']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Total Beneficiaries:

                                                                          <input name="totalben" type="text" id="totalben" value="<?php echo $_POST['totalben']; ?>" readonly="readonly" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td colspan="2"><strong>Project Team</strong></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project Team Leader:

                                                                          <input name="projteamlead" type="text" id="projteamlead" value="<?php echo $_POST['projteamlead']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Deputy Team Leader:

                                                                          <input name="projdepteamlead" type="text" id="projdepteamlead" value="<?php echo $_POST['projdepteamlead']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project Officer:

                                                                          <input name="projofficer" type="text" id="projofficer" value="<?php echo $_POST['projofficer']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Liason Officer:

                                                                          <input name="projliasonofficer" type="text" id="projliasonofficer" value="<?php echo $_POST['projliasonofficer']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td colspan="2"><strong>Meeting Dates</strong></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>First Project Meeting Date:

                                                                          <input name="projmeeting1" type="text" id="projmeeting1" value="<?php echo $_POST['projmeeting1']; ?>" />

                                                                        </p></td>

                                                                        <td><p>Third Project Meeting Date:

                                                                          <input name="projmeeting3" type="text" id="projmeeting3" value="<?php echo $_POST['projmeeting3']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Second Project Meeting

                                                                         

                                                                        Date:

                                                                            <input name="projmeeting2" type="text" id="projmeeting2" value="<?php echo $_POST['projmeeting2']; ?>" />

                                                                        </p></td>

                                                                        <td><p> </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td colspan="2"><strong>Other Dates</strong></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project Start Date:

                                                                            <label for="projstartdate"></label>

                                                                            <input name="projstartdate" type="text" id="projstartdate" value="<?php echo $_POST['projstartdate']; ?>" />

                                                                        </p></td>

                                                                        <td><p>MoU Signing Date:

                                                                          <input name="projmousigndate" type="text" id="projmousigndate" value="<?php echo $_POST['projmousigndate']; ?>" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr id="rowlines">

                                                                        <td><p>Project End Date:

                                                                            <label for="projstartdate"></label>

                                                                            <input name="projenddate" type="text" id="projenddate" value="<?php echo $_POST['projenddate']; ?>" />

                                                                        </p></td>

                                                                        <td><p> </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td> </td>

                                                                        <td> </td>

                                                                      </tr>

                                                                      <tr id="moredetails">

                                                                        <td colspan="2" id="moredetails"><strong>Upload Initial Project Documents/Pictures</strong></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td id="formcells"><p>Document/Picture One:

                                                                          <label for="Projdoc1"></label>

                                                                          <input type="file" name="Projdoc1" id="Projdoc1" />

                                                                        </p></td>

                                                                        <td id="formcells"><p>Document/Picture Four:

                                                                          <label for="Projimg1"></label>

                                                                          <input type="file" name="Projimg1" id="Projimg1" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td id="formcells"><p>Document/Picture Two:

                                                                          <label for="Projdoc2"></label>

                                                                          <input type="file" name="Projdoc2" id="Projdoc2" />

                                                                        </p></td>

                                                                        <td id="formcells"><p>Document/Picture Five:

                                                                          <label for="Projimg2"></label>

                                                                          <input type="file" name="Projimg2" id="Projimg2" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td id="formcells"><p>Document/Picture Three:

                                                                          <label for="Projdoc3"></label>

                                                                          <input type="file" name="Projdoc3" id="Projdoc3" />

                                                                        </p></td>

                                                                        <td id="formcells"><p>Document/Picture Six:

                                                                          <label for="Projimg3"></label>

                                                                          <input type="file" name="Projimg3" id="Projimg3" />

                                                                        </p></td>

                                                                      </tr>

                                                                      <tr>

                                                                        <td colspan="2"> </td>

                                                                      </tr>

                                                                    </table>

                                                                    <p>

                                                                      <input type="submit" name="btn_submit" id="btn_submit" value="Save &amp; Submit" />

                                                                    </p>

                                                                  </div>

                                                                  <!-- end .content -->

                                                                  <input type="hidden" name="MM_insert" value="submitpage" /> 

                                                                </form>

                                                              </fieldset>

                                                          • 27. Re: Save image path to MySQL and store file
                                                            Prince Mike Community Member

                                                            To try the online version of the web application please begin from the Project Core Details which has the link http://netdataflow.com/rbme/addprojectcore.php

                                                             

                                                            The site login details are provided by default

                                                             

                                                            Thank you

                                                            Mike

                                                            • 28. Re: Save image path to MySQL and store file
                                                              bregent CommunityMVP

                                                              The code in the online version does not match what you posted. For example, the form tag online is:

                                                              <form id="submitpage" name="submitpage" method="POST" action="/rbme/addprojectreview.php?">

                                                               

                                                              Are you uploading your page to the correct location? Is your upload failing?

                                                              • 29. Re: Save image path to MySQL and store file
                                                                Prince Mike Community Member

                                                                I am sorry. The online version has been updated now with the current codes

                                                                 

                                                                Mike

                                                                • 30. Re: Save image path to MySQL and store file
                                                                  bregent CommunityMVP

                                                                  I'm getting an "Unknown column 'Projdoc1' in 'field list'" . Check your database table and make sure a column of that name exists. Make sure it is spelled exactly the same.

                                                                  • 31. Re: Save image path to MySQL and store file
                                                                    Prince Mike Community Member

                                                                    Hi Bregent,

                                                                     

                                                                    Thank you for the observation. I am really sorry for that aswell. The Project table is now updated.

                                                                     

                                                                    Please try again.

                                                                     

                                                                    Mike

                                                                    • 32. Re: Save image path to MySQL and store file
                                                                      bregent CommunityMVP

                                                                      Please indicate which fields are mandatory. There are too many fields we need to fill in to test this. It would be helpful if you could modifify the form to include some default sample data, so we can test and see the results. Is there still an error message?

                                                                       

                                                                      As an aside, your form needs to include better validation that would allow the user to go back and fill in incorrect fields. As it is now, all of the fields are cleared when going back after recieving the server side error message.

                                                                      • 33. Re: Save image path to MySQL and store file
                                                                        Prince Mike Community Member

                                                                        Hi Bregent,

                                                                         

                                                                        Thank you for your response.

                                                                         

                                                                        Specifically all fields are required except the upload fields but based on your request I have added defaults values. Now only the fields with marked with asterisks by the label are compulsory. The dates fields are easy to fill as they have date picker in them. Once you click the date picker widget will pop up. The list/menu fields are easy to fill.

                                                                         

                                                                        With regards on the seconds paragraph "As an aside, your form needs to include better validation that would allow the user to go back and fill in incorrect fields. As it is now, all of the fields are cleared when going back after recieving the server side error message." , for now I dont know how to do this. What I did is make the last page called Review and Submit to be editable. Since its the last page, it shows the user all the entries and he can easily make changes before submitting the form. Is that a wrong method?

                                                                         

                                                                        The errors are still there

                                                                         

                                                                        Mike

                                                                        • 34. Re: Save image path to MySQL and store file
                                                                          bregent CommunityMVP

                                                                          OK, there are several things that are confusing. First of all, the 6 upload fields are labelled "Document/Picture One:", yet it appears that only 4-6 are setup to handle any type of attachment. Is this by design? Doesn't make sense to me.

                                                                          Next, I don't really understand this:

                                                                          $target = $target . basename( $_FILES['Projimg1']['name']);

                                                                          $target = $target . basename( $_FILES['Projimg2']['name']);

                                                                          $target = $target . basename( $_FILES['Projimg3']['name']); 

                                                                           

                                                                          You are concatenating 3 filenames together into the $target variable. How is that going to work? Unless I am not understanding something basic here, you probably need to create 3 target variables or just use basename( $_FILES['Projimg1']['name']); in the code as needed.

                                                                           

                                                                          I'm not sure how much php experience you have, but unless you are skilled, this form and workflow is too complicated to troubleshoot as is. The final form has 600 lines of code and the php script is big too. Create a simpler one page form with fewer fields so you can test the basic functionality  - file uploading - that you are attempting. Then you can incorporate it into your actual pages.

                                                                          • 35. Re: Save image path to MySQL and store file
                                                                            Prince Mike Community Member

                                                                            Hi Bregent,

                                                                             

                                                                            Thank you once more. Actually I thought every thing will work from the beginning hence the 6 file uploads. Based on your advice I am going to remove the first 5 and work with only one and see how it goes. Once it works, I will now add one after the other to see.

                                                                             

                                                                            With regards to this line of codes, was I supposed to write it this way for each fieldname:

                                                                             

                                                                            $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                      $target = $target . basename( $_FILES['Projimg1']['name']);

                                                                             

                                                                            $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                      $target = $target . basename( $_FILES['Projimg2']['name']);

                                                                             

                                                                            $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                      $target = $target . basename( $_FILES['Projimg3']['name']); 

                                                                             

                                                                            Instead of this other way that I earlier wrote it:

                                                                             

                                                                            $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                      $target = $target . basename( $_FILES['Projimg1']['name']);

                                                                                      $target = $target . basename( $_FILES['Projimg2']['name']);

                                                                                      $target = $target . basename( $_FILES['Projimg3']['name']); 

                                                                             

                                                                             

                                                                            On the area of Php skill, this is actually my first major project using PHP. Thanks to Dreamweaver.

                                                                             

                                                                            Thank you.

                                                                             

                                                                            Mike

                                                                            • 36. Re: Save image path to MySQL and store file
                                                                              Prince Mike Community Member

                                                                              Hi Bregent,

                                                                               

                                                                              Thank you once more. Actually I thought every thing will work from the beginning hence the 6 file uploads. Based on your advice I am going to remove the first 5 and work with only one and see how it goes. Once it works, I will now add one after the other to see.

                                                                               

                                                                              With regards to this line of codes, was I supposed to write it this way for each fieldname:

                                                                               

                                                                              $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                        $target = $target . basename( $_FILES['Projimg1']['name']);

                                                                               

                                                                              $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                        $target = $target . basename( $_FILES['Projimg2']['name']);

                                                                               

                                                                              $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                        $target = $target . basename( $_FILES['Projimg3']['name']); 

                                                                               

                                                                              Instead of this other way that I earlier wrote it:

                                                                               

                                                                              $target = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";  //This is the directory where images will be saved//

                                                                                        $target = $target . basename( $_FILES['Projimg1']['name']);

                                                                                        $target = $target . basename( $_FILES['Projimg2']['name']);

                                                                                        $target = $target . basename( $_FILES['Projimg3']['name']); 

                                                                               

                                                                               

                                                                              On the area of Php skill, this is actually my first major project using PHP. Thanks to Dreamweaver.

                                                                               

                                                                              Thank you.

                                                                               

                                                                              Mike

                                                                              • 37. Re: Save image path to MySQL and store file
                                                                                bregent CommunityMVP

                                                                                >With regards to this line of codes, was I supposed to write it this way for each fieldname:

                                                                                 

                                                                                Either way would yield the same, faulty results. The $target variable is used in several place in your code and used to specify the destination path/filename. You can't concatenate all 3 of the path/filenames into a single variable. You need to create 3 variables and replace their occurrence accordingly within your code:

                                                                                 

                                                                                $target1

                                                                                $target2

                                                                                $target3

                                                                                 

                                                                                There are probably more elegant ways of doing this, but start with that for now.

                                                                                • 38. Re: Save image path to MySQL and store file
                                                                                  Prince Mike Community Member

                                                                                  Hi Bregent,

                                                                                   

                                                                                  How are you doing?

                                                                                   

                                                                                  I have successfully resolved the image upload issue. Infact I am able to upload as much as 6 images at the same time and populate them on a read only page based on the ID of the project name that is selected. This is a complete new method from the one I was using before now.

                                                                                   

                                                                                  You can take a look by login into our demo site http://www.netdataflow.com/rbme/

                                                                                   

                                                                                  1. When you are at the home page, http://www.netdataflow.com/rbme/index.php,

                                                                                   

                                                                                  2. Click on My Projects and then at the top right click on Add New Project

                                                                                   

                                                                                  3. Fill the form as usual with the default details. For project name, please enter one as I have made it unique to avaoid double entry.

                                                                                   

                                                                                  4. When you are done, you will presented with a new page where you can upload one or two images. This is the last entry page

                                                                                   

                                                                                  5. When you are done please go back to My Project page and click on the project you just added. This should be the last on the list. There you will see the picture.

                                                                                   

                                                                                  Please kindly advice on my performance.

                                                                                   

                                                                                  Thank you in advance

                                                                                   

                                                                                  Mike

                                                                                  • 39. Re: Save image path to MySQL and store file
                                                                                    Prince Mike Community Member

                                                                                    When I am done with the entire project, I will encrypt the pages before uploading them to the production site