Jump to content

What am I doing wrong?


daebat

Recommended Posts

I did a big upgrade to my CMS and now the editing of an upload doesn't seem to work.  The id is pulled from a list on the previous page and is functional.  Here is the form:

 

$id=$_GET['id'];

$data = mysql_query("SELECT * FROM headerimg WHERE id = '$id'") or die(mysql_error());

while($info = mysql_fetch_array( $data ))
{
echo "
<div id='edit'>

<form method='post' action='headerimgeditprocess.php?id=".$id ."' enctype='multipart/form-data'>
<fieldset>
<legend>".$info['title'] ."</legend>

         <table>

             <tr><td colspan='2' style='text-align:center'><img src='../upload/headerimg/".$info['image'] ."' width='300'><br /><br /></tr></td>
                         <td>
              Title:</td>
            <td>
            <input type='text' name='title' value='".$info['title'] ."'>
             </td></tr>
             <tr><td>
            Image:
            </td><td>
            <input type='file' name='image'></td></tr>
            </table>            
            <br/>
            <br/>
            <input TYPE='submit' name='upload' title='Add data to the Database' value='Submit'/>
         </fieldset>
          </form>

 

Here is the processor:

 

$target = "/var/chroot/home/content/87/6409087/html/upload/headerimg/";

//This gets all the other information from the form
$title=$_POST['title'];
$id=$_GET['id'];

if ($image != ''){
$image = ($_FILES['image']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}
mysql_query("UPDATE headerimg SET image ='$image' WHERE id ='$id'");
}

//Writes the information to the database

mysql_query("UPDATE headerimg SET title = '$title' WHERE id ='$id' ");

?>
<p>Update Successful... <a href="../main.php">click here</a> to return to the administration area.</p>

 

 

 

Link to comment
Share on other sites

I just didn't include the rest of the html.  I'm pretty sure that what's going on is that something is wrong with the if statement.  Basically it's saying check to see if the upload field is empty.  If it has data then overwrite what's in the database.  It seems that it isn't being passed on.  Not sure why?  I can update the Title portion just fine.  The image part is what isn't working.  (btw I use the same code (without the if statement) for the first time upload form (this is the edit form).

Link to comment
Share on other sites

I just didn't include the rest of the html.  I'm pretty sure that what's going on is that something is wrong with the if statement.  Basically it's saying check to see if the upload field is empty.  If it has data then overwrite what's in the database.  It seems that it isn't being passed on.  Not sure why?  I can update the Title portion just fine.  The image part is what isn't working.  (btw I use the same code (without the if statement) for the first time upload form (this is the edit form).

[/code]

ah ok so you just didn't copy that.

small question: Where does your $image get's it's value from. As far as i can see $image is empty because i can't spot something that assigns a value to it. making your if statement worthless because it will never enter the first part of the ifstatement because it's always equal to ' '

 

Maybe also use  if(empty($image)){} or if(!empty($image)){} depending on what you want

 

Just to proof this: run this:

//This gets all the other information from the form
$title=$_POST['title'];
$id=$_GET['id'];

echo 'output value of image var: '.$image; //i added this
//you need to put here something to assign a value you expect for your image variable

if ($image != ''){

      $image = ($_FILES['image']['name']);
              foreach($_FILES as $file) {
                     move_uploaded_file($file['tmp_name'], $target . $file['name']);
               }else{//i added an else clause
                     echo 'if you see this it means variable image is empty';
               }
               mysql_query("UPDATE headerimg SET image ='$image' WHERE id ='$id'");
        }

//Writes the information to the database

mysql_query("UPDATE headerimg SET title = '$title' WHERE id ='$id' ");

?>
<p>Update Successful... <a href="../main.php">click here</a> to return to the administration area.</p>

 

 

[/code]

Link to comment
Share on other sites

Where does your $image get's it's value from.

 

The top form.  There is a title field and a file upload field. 

 

The thing is, I have this same set up working in a previous install of my CMS but it's just more complicated; the only difference is that I have a session storing the ftp info rather than stating it... here is the code:

 

The Form:

 

$data = mysql_query("SELECT * FROM graphicscatalog WHERE id = '$id'") or die(mysql_error());

//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
echo "
<div id='edit'>
<form method='post' action='graphicscatalogeditprocess.php?id=".$id ."' enctype='multipart/form-data'>
<fieldset>
<legend>".$info['title'] ."</legend>

         <table>

             <tr><td colspan='2' style='text-align:center'><img src='upload/graphicscatalog/".$info['thumb'] ."'><br /><br /></tr></td>
             <tr><td>Order #:</td>
              
            <td>
             <input type='text' name='ordering' value='".$info['ordering'] ."'>
            </td></tr>         
             <tr>
             <td>
              Title:</td>
            <td>
            <input type='text' name='title' value='".$info['title'] ."'>
             </td></tr>
             <td>
              Description:</td>
            <td>
            <input type='text' name='description' value='".$info['description'] ."'>
             </td></tr>
             <tr><td>
            Image:
            </td><td>
            <input type='file' name='image'></td></tr>
            <tr><td>
              Image Thumbnail:
            </td><td>
            <input type='file' name='thumb'></td></tr>
           <tr><td>
            EPS:
            </td><td>
            <input type='file' name='eps'></td></tr>
           <tr><td>
            PDF:
            </td><td>
            <input type='file' name='pdf'></td></tr>
            <tr><td>
            PNG:
            </td><td>
            <input type='file' name='png'></td></tr>          
            </table>            
            <br/>
            <br/>
            <input TYPE='submit' name='upload' title='Add data to the Database' value='Submit'/>
         </fieldset>
          </form>
          <a href='graphicscataloglist.php'><img src='images/backButton.jpg'></a>
          </div><br />";

 

The Processor:

 



$target = "/home/path/public_html/sgktoolbox/upload/graphicscatalog/";


//This gets all the other information from the form
$ordering=$_POST['ordering'];
$title=$_POST['title'];
$description=$_POST['description'];
$id=$_GET['id'];

// Connects to your Database
mysql_connect("localhost", "user", "pass") or die(mysql_error()) ;
mysql_select_db("database") or die(mysql_error()) ;


if ($image != ''){
$image = ($_FILES['image']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}
mysql_query("UPDATE graphicscatalog SET image ='$image' WHERE id ='$id'");
}
if ($thumb != ''){
$thumb = ($_FILES['thumb']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}
mysql_query("UPDATE graphicscatalog SET thumb ='$thumb' WHERE id ='$id'");
}
if ($eps !=''){
$eps=($_FILES['eps']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}
mysql_query("UPDATE graphicscatalog SET eps ='$eps' WHERE id ='$id'");
}
if ($pdf !=''){
$pdf=($_FILES['pdf']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}
mysql_query("UPDATE graphicscatalog SET pdf ='$pdf' WHERE id ='$id'");
}
if ($png !=''){
$png=($_FILES['png']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}
mysql_query("UPDATE graphicscatalog SET png ='$png' WHERE id ='$id'");
}


//Writes the information to the database

mysql_query("UPDATE graphicscatalog SET ordering = '$ordering', title = '$title', description = '$description' WHERE id ='$id' ");

  

 

I've gone line by line and can't seem to see what's triggering the problem.  Could it be my tables in the database?  I'm pretty sure they are the same but I could be wrong.  Here is a screen cap...

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

well still your $image is empty so it will not run the first part of the if statement. I hope you see that (it needs to get a value to run the first part)

look:

 

if ($image != ''){ // will always be empty so it will never run the stuff below. 
$image = ($_FILES['image']['name']);
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}

what happends if you try this:

 

$image = ($_FILES['image']['name']);//let image get a value
if ($image != ''){ // atleast image now is being assigned with a value. not sure if this is right for your situation, but i hope you get the idea
foreach($_FILES as $file) {
    move_uploaded_file($file['tmp_name'], $target . $file['name']);
}

 

the same is true for all those variables like $png and stuff they all have an empty value, i bet you need to places the $_FILES['xxx'] above it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.