STORE PATH TO IMAGE IN MYSQL FIELD AFTER IMAGE UPLOAD...

I have an image upload form that works.

Now I would like to add code to that form to transfer the path to the uploaded image into a MySQL text field.

Here is the page that holds the form.  There is a comment on line 25 showing where the insertion code should be placed  This comment says:

// ... code to insert the path to the image file into a MySql datbase field "pic1"
//  (this is "pic and numeral one") in a table called "cneblg" should be placed here.
//  The resulting entry into the MySQL field "pic1" should generate this, for example:
//  <img src="http://clgus.com/clgus/pics/1201483061.jpg" hspace="10" vspace="5" align="left" border=1>

The code for the page:
------------------------
<?php
include ($_SERVER['DOCUMENT_ROOT']."/clgus/pics/upload_class.php"); //classes is the map where the class file is stored (one above the root)

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

$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/clgus/pics/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".jpg", ".png", ".gif"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
            
if(isset($_POST['Submit'])) {
      $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
      $my_upload->the_file = $_FILES['upload']['name'];
      $my_upload->http_error = $_FILES['upload']['error'];
      $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
      $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
      $new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
      if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
            $full_path = $my_upload->upload_dir.$my_upload->file_copy;
            $info = $my_upload->get_uploaded_file_info($full_path);
            
// ... code to insert the path to the image file into a MySql datbase field "pic1"
//  (this is "pic and numeral one") in a table called "cneblg" should be placed here
//  the resulting entry into the MySQL field "pic1" should generate this, for example:
//  <img src="http://clgus.com/clgus/pics/1201483061.jpg" hspace="10" vspace="5" align="left" border=1>

      }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload Foto</title>
<style type="text/css">
<!--
label {
      float:left;
      display:block;
      width:120px;
}
input {
      float:left;
}
-->
</style>
<link href="../../../css/thin_border.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
      font-weight: bold;
      font-size: 12px;
}
.style2 {font-size: 12px}
-->
</style>
</head>

<body bgcolor="#E8CA24">
<table width="707" height="281" border="0" align="center" bgcolor="#FFFFCC" class="thin_border_gray_narrow">
  <tr>
    <td width="701" height="26">&nbsp;</td>
  </tr>
  <tr>
    <td height="25" valign="top">
<p>&nbsp;</p>
    </td>
  </tr>
  <tr>
    <td height="53"><h3 align="center"><font color="#FF6600" size="2" face="Verdana, Arial, Helvetica, sans-serif">Image  Upload<br>
        </font><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Max.
        file sze= <?php echo $max_size; ?> bytes, or 300 pixels wide or high.<br>
        <a href="http://www.shrinkpictures.com/">Click here for help to resize your picture</a> </font></h3></td>
  </tr>
  <tr>
    <td height="101" valign="top">
      <form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['file:///C|/Documents%20and%20Settings/Curt/My%20Documents/Downloads/UploadScript/PHP_SELF']; ?>">
        <table width="701" border="0" align="center">
          <tr>
            <td width="347"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>">
              </font></td>
            <td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
          </tr>
          <tr>
            <td height="27" valign="middle"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Click &quot;Browse&quot; to select a picture to upload: </span></font></div></td>
            <td valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="file" name="upload" size="30">
            </font></td>
          </tr>
          <tr>
            <td><div align="left">
                <font face="Verdana, Arial, Helvetica, sans-serif"><span class="style2">
                <label for="check"></label>
                </span></font>                                </div></td>
            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;
              </font></td>
          </tr>
          <tr>
            <td height="21"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><span class="style2"><strong>Verify the filename? (Recommend):</strong></span></font> </div></td>
            <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
                <input name="check" type="checkbox" value="y" checked>
            </font></div></td>
          </tr>
          <tr>
            <td height="40" colspan="2"><div align="center">
                <blockquote>
                  <blockquote>
                    <blockquote>
                      <blockquote>
                        <blockquote>
                          <blockquote>
                            <blockquote>
                              <p>
                                <input type="submit" name="Submit" value="Send it Now!">
                              </p>
                            </blockquote>
                          </blockquote>
                        </blockquote>
                      </blockquote>
                    </blockquote>
                  </blockquote>
                </blockquote>
            </div>
              <div align="left"></div></td>
          </tr>
        </table>
      </form></td>
  </tr>
  <tr>
    <td height="21" valign="top"> <p><?php echo $my_upload->show_error_string(); ?>
      <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?>
      <br>
    </p></td>
  </tr>
</table>
<h3><br>
</h3>
<br clear="all">
<p>&nbsp; </p>
</body>
</html>
------------------------------
I have searched the web for answers, but have not found anything that I'm able to understand and implement.

Expert help is appreciated.

Curt L. Gustafsson
cgustafAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

adrpoCommented:
Hi,

You might go like this, see below...
Have a look for more info here:
http://www.tizag.com/mysqlTutorial/

Cheers,
za-k/

// Make a MySQL Connection - change the parameters to suite your DB
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
// select the database you want 
mysql_select_db("my_db") or die(mysql_error());
 
// Generate the insert into table "cneblg", field "pic1" as text 
$queryInsert = "INSERT INTO cnebbl(pic1) VALUES('" + $full_path + "')";
// run the insert into the database
mysql_query($queryInsert) or die(mysql_error());  
// work done...

Open in new window

0
cgustafAuthor Commented:
Hi adrpo,

Thank you for your comment.

I have begun testing it, but have not yet been able to insert a path into the MySQL database.  I'll keep trying for a while, and let you know.

Curt L. Gustafsson
0
adrpoCommented:

Hi,

There is a small error in there "cnebbl" should be "cneblg" as you say:
$queryInsert = "INSERT INTO cnebbl(pic1) VALUES('" + $full_path + "')";
should be:
$queryInsert = "INSERT INTO cneblg(pic1) VALUES('" + $full_path + "')";

In rest, you will need to edit:
// Make a MySQL Connection - change the parameters to suite your DB
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
See more here:
http://se.php.net/mysql_connect

// select the database you want
mysql_select_db("my_db") or die(mysql_error());
See more here:
http://se.php.net/manual/en/function.mysql-select-db.php

If you put the correct MySQL hostname, user, pass and db it will work!

Cheers,
za-k/
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

cgustafAuthor Commented:
Hi adrpo,

I have attempted to include the code you sent into the page, and I tried quite a few variants.

The connection and the database select are at the top of the code, lines 1-7.

The insert commands are on lines 34-37, like this:

$queryInsert = "INSERT INTO cneblg (pic1) VALUES('" + $full_path + "')";
// run the insert into the database
mysql_query($queryInsert) or die(mysql_error());  
// work done...

When thes two lines of code are added, a persistent connection error seems to appear.  The error message is:  "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1."  I have not been able to solve this.

However, when the insert commands are removed, the error does not appear.  The image is uploaded, but no data (the path to the image) is of course added to the "pic1" field in the MySQL database.

What do you think should be done?

The entire code, including the connection and the insert commands are below.  I use Dreamweaver MX.

<?php require_once('../Connections/cneblg.php'); ?>
<?php
mysql_select_db($database_cneblg, $cneblg);
$query_Recordset1 = "SELECT * FROM cneblg";
$Recordset1 = mysql_query($query_Recordset1, $cneblg) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
include ($_SERVER['DOCUMENT_ROOT']."/clgus/pics/upload_class.php"); //classes is the map where the class file is stored (one above the root)

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

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

$queryInsert = "INSERT INTO cneblg (pic1) VALUES('" + $full_path + "')";
// run the insert into the database
mysql_query($queryInsert) or die(mysql_error());  
// work done...
      
      
      }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload Foto</title>
<style type="text/css">
<!--
label {
      float:left;
      display:block;
      width:120px;
}
input {
      float:left;
}
-->
</style>
<link href="../../../css/thin_border.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
      font-weight: bold;
      font-size: 12px;
}
.style2 {font-size: 12px}
-->
</style>
</head>

<body bgcolor="#E8CA24">
<table width="707" height="366" border="0" align="center" bgcolor="#FFFFCC" class="thin_border_gray_narrow">
  <tr>
    <td width="701"><img src="ccl_ribbon_new_700.png" width="700" height="120"></td>
  </tr>
  <tr>
    <td valign="top">
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="../cneblg.php">To the story page</a> </font></p>
    </td>
  </tr>
  <tr>
    <td height="53"><h3 align="center"><font color="#FF6600" size="2" face="Verdana, Arial, Helvetica, sans-serif">Covenant Class Mission  Upload<br>
        </font><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Max.
        file sze= <?php echo $max_size; ?> bytes, or 300 pixels wide or high.<br>
        <a href="http://www.shrinkpictures.com/">Click here for help to resize your picture</a> </font></h3></td>
  </tr>
  <tr>
    <td height="101" valign="top">
      <form name="form1" enctype="multipart/form-data" method="POST">
        <table width="701" border="0" align="center">
          <tr>
            <td width="347"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>">
              </font></td>
            <td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
          </tr>
          <tr>
            <td height="27" valign="middle"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Click &quot;Browse&quot; to select a picture to upload: </span></font></div></td>
            <td valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="file" name="upload" size="30">
            </font></td>
          </tr>
          <tr>
            <td><div align="left">
                <font face="Verdana, Arial, Helvetica, sans-serif"><span class="style2">
                <label for="check"></label>
                </span></font>                                </div></td>
            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;
              </font></td>
          </tr>
          <tr>
            <td height="21"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><span class="style2"><strong>Verify the filename? (Recommend):</strong></span></font> </div></td>
            <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
                <input name="check" type="checkbox" value="y" checked>
            </font></div></td>
          </tr>
          <tr>
            <td height="40" colspan="2"><div align="center">
                <blockquote>
                  <blockquote>
                    <blockquote>
                      <blockquote>
                        <blockquote>
                          <blockquote>
                            <blockquote>
                              <p>
                                <input type="submit" name="Submit" value="Send it Now!">
                              </p>
                            </blockquote>
                          </blockquote>
                        </blockquote>
                      </blockquote>
                    </blockquote>
                  </blockquote>
                </blockquote>
            </div>
              <div align="left"></div></td>
          </tr>
        </table>
       
      </form></td>
  </tr>
  <tr>
    <td height="21" valign="top"> <p><?php echo $my_upload->show_error_string(); ?>
      <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?>
      <br>
    </p></td>
  </tr>
</table>
<h3><br>
</h3>
<br clear="all">
<p>&nbsp; </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
0
cgustafAuthor Commented:
Thanks again for your input.

Here is what I have now, after having entered what you sent.  It appears that the connection works, ans well as the db select and the insert command.  However, the path to the image is not inserted into the MySQL field (pic1).

In this version, the connection data is of course wide open.  This may not be so practical.  But it's OK for now in order to get the code working.

This is from the top to the end of the insert operation:

<?php
include ($_SERVER['DOCUMENT_ROOT']."/clgus/pics/upload_class.php"); //classes is the map where the class file is stored (one above the root)

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

$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/clgus/pics/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".jpg", ".png", ".gif"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
            
if(isset($_POST['Submit'])) {
      $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
      $my_upload->the_file = $_FILES['upload']['name'];
      $my_upload->http_error = $_FILES['upload']['error'];
      $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
      $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
      $new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
      if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
            $full_path = $my_upload->upload_dir.$my_upload->file_copy;
            $info = $my_upload->get_uploaded_file_info($full_path);
            // ... or do something like insert the filename to the database
            
mysql_connect("ibtpartners.org", "ibtpartners-2", "hyttorna6") or die(mysql_error());
mysql_select_db("ibtpartners-2") or die(mysql_error());
$queryInsert = "INSERT INTO cneblg(pic1) VALUES('" + $full_path + "')";

            
      }
}
?>
0
cgustafAuthor Commented:
I tried hard coding a value for the insert command -- see below.  This, too, did not work (nothing inserted, in other words), so there is something else that does not work.

mysql_connect("ibtpartners.org", "ibtpartners-2", "hyttorna6") or die(mysql_error());
mysql_select_db("ibtpartners-2") or die(mysql_error());
// $queryInsert = "INSERT INTO cneblg(pic1) VALUES('" + $full_path + "')";
// hard coded value
$queryInsert = "INSERT INTO cneblg(pic1) VALUES(../temp/image_34.jpg)";
0
adrpoCommented:

Ok,

Wait a minute. What is the data type of the cneblg.pic1 in your database?
I asume is some kind of VARCHAR or text as it should be a path in there.
If you try to add '0' and it doen't work then it might be an integer in there.
Did you had a look?

Also because your error has '0' it means that the variable $full_path is 0.
See what is in the variable $full_path.

This one might work, but you need to make it a string, otherwise it won't be accepted:
$queryInsert = "INSERT INTO cneblg(pic1) VALUES(../temp/image_34.jpg)";
should be:
$queryInsert = "INSERT INTO cneblg(pic1) VALUES('../temp/image_34.jpg')";

Cheers,
zak/
0
cgustafAuthor Commented:
Thanks for looking at this again.

I had the data type in "pic1" as MEDIUMTEXT, but changed it later to VARCHAR.  That change did not make any difference, though.  I did not expect it would.  The filenames for the pictures consist of numerals, however, like 1201468321.jpg, but this can be treated as text.  At least that's my thought, since the filename is definitely not an integer with the ".jpg" in it.

For a moment, I'd like to take another turn on this matter.  As I mentioned, I work in Dreamweaver (MX 2004).  There, I have experiemented with the following INSERT command:

$insertSQL = sprintf("INSERT INTO cneblg (text, pic1) VALUES (%s, %s)",
               GetSQLValueString($_POST['text'], "text"),
              GetSQLValueString($_POST['pic1'], "('" + $full_path + "')"));

Don't know if you are familiar with Dreamweaver code, but maybe that does not make any difference as far as my question is concerned.  Here it is:

In the above INSERT the first string, GetSQLValueString($_POST['text'], "text"), , works -- i.e., the texts entered into the formfield "text" are inserted into the database field "text".

However, the second INSERT string does not work.  Nothing happens.  I think the reason for this is that the syntax in the string is not right as far as the variable, ("('" + $full_path + "')"), is concerned.

I wonder:

1.  Do you know the correct syntax for the expression of the variable in this second INSERT statement?

2.  Does it matter where in the code this INSERT statement is located?  In other words should the creation of the variable be *above* the INSERT statement, or can it be *below*?  Or, does this matter at all -- that is, can it be either above or below?

Here is the entire code:

<?php require_once('../Connections/cneblg.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
 
$insertSQL = sprintf("INSERT INTO cneblg (text, pic1) VALUES (%s, %s)",
         GetSQLValueString($_POST['text'], "text"),
        GetSQLValueString($_POST['pic1'], "('" + $full_path + "')"));
 
  mysql_select_db($database_cneblg, $cneblg);
  $Result1 = mysql_query($insertSQL, $cneblg) or die(mysql_error());
}

mysql_select_db($database_cneblg, $cneblg);
$query_Recordset1 = "SELECT * FROM cneblg";
$Recordset1 = mysql_query($query_Recordset1, $cneblg) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
include ($_SERVER['DOCUMENT_ROOT']."/clgus/pics/upload_class.php"); //classes is the map where the class file is stored (one above the root)

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

$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/clgus/pics/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".jpg", ".png", ".gif"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
            
if(isset($_POST['Submit'])) {
      $my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
      $my_upload->the_file = $_FILES['upload']['name'];
      $my_upload->http_error = $_FILES['upload']['error'];
      $my_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
      $my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
      $new_name = (isset($_POST['name'])) ? $_POST['name'] : "";
      if ($my_upload->upload($new_name)) { // new name is an additional filename information, use this to rename the uploaded file
            $full_path = $my_upload->upload_dir.$my_upload->file_copy;
            $info = $my_upload->get_uploaded_file_info($full_path);
            // ... or do something like insert the filename to the database
            
// mysql_connect("ibtpartners.org", "ibtpartners-2", "hyttorna6") or die(mysql_error());
//mysql_select_db("ibtpartners-2") or die(mysql_error());
// $queryInsert = "INSERT INTO cneblg(pic1) VALUES('" + $full_path + "')";

//$queryInsert = "INSERT INTO cneblg(pic1) VALUES('../pics/image_34.jpg')";
            
      }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload Foto</title>
<style type="text/css">
<!--
label {
      float:left;
      display:block;
      width:120px;
}
input {
      float:left;
}
-->
</style>
<link href="../../../css/thin_border.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
      font-weight: bold;
      font-size: 12px;
}
.style2 {font-size: 12px}
-->
</style>
</head>

<body bgcolor="#E8CA24">
<table width="707" height="366" border="0" align="center" bgcolor="#FFFFCC" class="thin_border_gray_narrow">
  <tr>
    <td width="701"><img src="ccl_ribbon_new_700.png" width="700" height="120"></td>
  </tr>
  <tr>
    <td valign="top">
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="../cneblg.php">To the story page</a> </font></p>
    </td>
  </tr>
  <tr>
    <td height="53"><h3 align="center"><font color="#FF6600" size="2" face="Verdana, Arial, Helvetica, sans-serif">Covenant Class Mission  Upload<br>
        </font><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Max.
        file sze= <?php echo $max_size; ?> bytes, or 300 pixels wide or high.<br>
        <a href="http://www.shrinkpictures.com/">Click here for help to resize your picture</a> </font></h3></td>
  </tr>
  <tr>
    <td height="101" valign="top">
      <form name="form1" enctype="multipart/form-data" method="POST" action="<?php echo $editFormAction; ?>">
        <table width="701" border="0" align="center">
          <tr>
            <td width="347"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>">
              </font></td>
            <td width="344"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
          </tr>
          <tr>
            <td height="27" valign="middle"><div align="right">Text:</div></td>
            <td valign="top"><textarea name="text" cols="35" id="text"></textarea></td>
          </tr>
          <tr>
            <td height="27" valign="middle">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
          <tr>
            <td height="27" valign="middle"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Click &quot;Browse&quot; to select a picture to upload: </span></font></div></td>
            <td valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
              <input type="file" name="upload" size="30">
            </font></td>
          </tr>
          <tr>
            <td><div align="left">
                <font face="Verdana, Arial, Helvetica, sans-serif"><span class="style2">
                <label for="check"></label>
                </span></font>                                </div></td>
            <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;
              </font></td>
          </tr>
          <tr>
            <td height="21"><div align="right"><font face="Verdana, Arial, Helvetica, sans-serif"><span class="style2"><strong>Verify the filename? (Recommend):</strong></span></font> </div></td>
            <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
                <input name="check" type="checkbox" value="y" checked>
            </font></div></td>
          </tr>
          <tr>
            <td height="40" colspan="2"><div align="center">
                <blockquote>
                  <blockquote>
                    <blockquote>
                      <blockquote>
                        <blockquote>
                          <blockquote>
                            <blockquote>
                              <p>
                                <input type="submit" name="Submit" value="Send it Now!">
                              </p>
                            </blockquote>
                          </blockquote>
                        </blockquote>
                      </blockquote>
                    </blockquote>
                  </blockquote>
                </blockquote>
            </div>
              <div align="left"></div></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1">
      </form></td>
  </tr>
  <tr>
    <td height="21" valign="top"> <p><?php echo $my_upload->show_error_string(); ?>
      <?php if (isset($info)) echo "<blockquote>".nl2br($info)."</blockquote>"; ?>
      <br>
    </p></td>
  </tr>
</table>
<h3><br>
</h3>
<br clear="all">
<p>&nbsp; </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>


 
0
cgustafAuthor Commented:
See my previous entry.

Here I just wanted to give you the URL to the page for which I just sent you the code:  

http://clgus.com/clgus/pics/upload.php?
0
adrpoCommented:

1. Should be:
GetSQLValueString($ful_path, "text");
As far as i can see you have no 'pic1' in the POST data.

2.  Does it matter where in the code this INSERT statement is located?  In other words should the creation of the variable be *above* the INSERT statement, or can it be *below*?  Or, does this matter at all -- that is, can it be either above or below?

It matters A LOT where the code for insert is.
$full_path should be defined and set when you do the insert.
Otherwise you will get an error or insert null or 0 in the db.

I wonder if you need to use . instead of + in PHP:
The statement should look like this after all processing:
INSERT INTO cneblg (text, pic1) VALUES ('the text', 'the full path');
Print the statement and see where the problem is.

Cheers,
za-k/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cgustafAuthor Commented:
OK  Thanks.

This one:  GetSQLValueString($ful_path, "text");   brought some results when the INSERT statements were moved below the section that defines the variable $full_path.

Here is the INSERT code section that works -- to a point.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO cneblg (text, pic1) VALUES (%s, %s)",                     GetSQLValueString($_POST['text'], "text"),
      GetSQLValueString($full_path, "text"));

Now, $full_path does not give me quite the right path, or perhaps better, the needed path.  Part of the path displays what is needed, but the early part needs to be deleted.  Here is what $full_path displays:

/home/com/clgus/html/clgus/pics/1201634039.jpg

What we need is this:

<img src="../clgus/pics/1201634039.jpg" hspace="10" vspace="5" align="left" border=1>

The following is the path that should result from the variable ($full_path, for example).  The rest of the information surrounding the output from the variable is text that must somehow be provided as the output from the variable is placed into the "pic1" field in the database.

Theses text parts that need to be "enclosed" with the variable output are:

>img src="..      the $full_path variable out put here       " hspace="10" vspace="5" align="left" border=1>

So, the actual $full_path variable output should be:

/clgus/pics/1201634039.jpg

Could one configure the needed text parts into two separate variables that could seamlessly surrond the $full_path  (or another variable reconfigured to provided exactly the path output needed for the image path in "pic1")?

Again, the final output should look like this:

<img src="../clgus/pics/1201634039.jpg" hspace="10" vspace="5" align="left" border=1>

Where   >img src="..   is perhaps contained in a variable $img_src  

and where   " hspace="10" vspace="5" align="left" border=1>   is perhaps contained in a variable $hspace  .

In other words the output could perhaps be generated like this:  $img_src$full_path$hspace  .  There must not be any spaces in the output string resulting from the concatenation of the 3 variables, however.

Maybe this is a mouthful, but it would sure be nice if it could be worked out.

If you can help to get this done, I'll up the points!

Maybe it is a lot easier than I think it is!

Curt L. Gustafsson





0
cgustafAuthor Commented:
Hi again,

I now have the two text segments for the path in separate variables.  Have not tried to concatenate them yet, and have not isolated the filename into one single variable.

Curt L. Gustafsson
0
cgustafAuthor Commented:
Now I have isolated the filename into a variable, $my_file .

Will try to concatenate the three variables.

Curt L. Gustafsson
0
cgustafAuthor Commented:
OK Got it!

Concatenating variables with [.] works wonders.

Problem solved.

Thanks for your help.

Curt L. Gustafsson
0
adrpoCommented:

Glad you could fix it and I could be of some help.

PLEASE:
 Change all the passwords for the db you gave here!!
 You need to do that because you also gave the hostname of your computer.
 Or, in alternative make MySQL listen only to local connections.

Cheers,
za-k/
0
cgustafAuthor Commented:
Thank you for helping me get onto the right path.

I have asked for the question to be deleted since I don't see a way to edit entries that need to edited if the question is to be left on the site.

Greetings,
Curt L. Gustafsson
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.