Page 1 of 1

Creating an update image page

Posted: Tue Oct 07, 2008 4:30 pm
by slaterino
Hi I have created an image gallery and have created a cms page for adding images and also an edit page for modifying the image details. However, I seem to be having problems creating a section where the image can be updated. This is the code I have at the moment, but all it is producing is blank data and no errors. Can anyone see any problems with the code? I've got a feeling it must be to do with the position of a closed bracket but I've tried many different combinations and nothing seems to work. If someone could have a look that would be amazing! Thanks

Code: Select all

<?php
 
include("../lib/config.php");
error_reporting(0);
   $id = $_GET['id'];
 
   if(isset($_POST['submit']))
  {
 
      $member = $_POST['member'];
      $role = $_POST['role'];
      $sequence = $_POST['sequence'];
      
      if (isset ($_FILES['new_image']))
          {
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "../../images/committee_big/".$imagename;
              $member = $_POST['txtMember'];
              $role = $_POST['txtRole'];
              $sequence = $_POST['sequence'];
              move_uploaded_file($source, $target);
 
              $imagepath = $imagename;
              $save = "../../images/committee/" . $imagepath; //This is the new file you saving
              $file = "../../images/committee_big/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
 
              $modwidth = 150; 
 
              $diff = $width / $modwidth;
 
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
 
              imagejpeg($tn, $save, 100) ; 
 
              $save = "../../images/committee/" . $imagepath; //This is the new file you saving
              $file = "../../images/committee_big/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
 
              $modwidth = 80; 
 
              $diff = $width / $modwidth;
 
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
 
              imagejpeg($tn, $save, 100) ; 
              }
              
if(!get_magic_quotes_gpc())
{
$imagename = addslashes($imagename);
$imagepath = addslashes($imagepath);
}
 
         $result = mysql_query("UPDATE committee SET member='$member', role='$role', sequence='$sequence' WHERE id='$id' ",$connect);
 
          echo "<b>Thank you! Committee Member UPDATED Successfully!<br />You'll be redirected to Home Page after (4) Seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
}
elseif($id)
{
 
        $result = mysql_query("SELECT * FROM committee WHERE id='$id' ",$connect);
        while($myrow = mysql_fetch_assoc($result))
             {
                $member = $myrow["member"];
                $role = $myrow["role"];
                $sequence = $myrow["sequence"];
?>
<h3>::Edit Committee Member</h3>
 
<form method="post" action="<?php echo $PHP_SELF ?>">
<table>
<input type="hidden" name="id" value="<? echo $myrow['id']?>">
<tr>
<td>Member:</td><td><input name="member" size="40" maxlength="255" value="<? echo $member; ?>"></td></tr>
<tr>
<td>Role: </td><td><input name="role"  size="40" maxlength="255" value="<? echo $role; ?>" /></td></tr>
<tr>
<td>Order: </td><td><input name="sequence" size="40" maxlength="255" value="<? echo $sequence; ?>"></td></tr>
<tr>
<td>Image:</td><td><?php echo "<img src='../../images/committee/".$myrow['path']."'>"; ?></td>
</tr>
<tr>
<td>Add Image: </td><td><input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /><br /></td></tr>
<br />
</table><br />
<div align="center"><input type="submit" name="submit" value="Update Member"></div>
</form>
 
<?
              }
  }
  echo "<br /><a href=\"javascript&#058;self.history.back();\"><-- Go Back</a>";
?>

Re: Creating an update image page

Posted: Wed Oct 08, 2008 3:38 am
by aceconcepts
What are trying to do exactly - give some more detail?

A url would help also :D

Re: Creating an update image page

Posted: Wed Oct 08, 2008 3:42 am
by slaterino
Hi,
I'm just trying to create a page where I can modify entries in a gallery. I've now turned error reporting on on this page and the form is loading. However, when I click submit a page loads up with this message:

Code: Select all

The requested URL /login/edit_committee/<br /><b>Notice</b>: Undefined variable: PHP_SELF in <b>/home/sites/thedaffodilsociety.com/public_html/login/edit_committee/edit.php</b> on line <b>111</b><br /> was not found on this server.
Have you ever seen this before? I don't understand why it's trying to load this address. Could this be a problem with a closed bracket being out of place? If you have any ideas please let me know.

Re: Creating an update image page

Posted: Wed Oct 08, 2008 3:47 am
by aceconcepts
If a bracket was out of place it would tell you.

The message you're receiving is telling you that a variable (PHP_SELF) is undefined (not set correctly).

I would imagine you are posting a form to itself, right?

e.g.

Code: Select all

<form method="POST" action="PHP_SELF">
Is this right?

Re: Creating an update image page

Posted: Wed Oct 08, 2008 3:57 am
by Paul Arnold
Change this line (81):

Code: Select all

 
<form method="post" action="<?php echo $PHP_SELF ?>">
 
to this:

Code: Select all

 
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
 

Re: Creating an update image page

Posted: Wed Oct 08, 2008 4:00 am
by aceconcepts
If this is the case, you can simply leave out the 'action' of the form. It will default to itself.

Re: Creating an update image page

Posted: Wed Oct 08, 2008 4:36 am
by slaterino
Okay,
I feel like I'm making some progress, but am now getting the following error message:

Code: Select all

Notice: Undefined index: id in /home/sites/mydomain.com/public_html/login/edit_committee/edit.php on line 35
 
Notice: Undefined variable: imagename in /home/sites/mydomain.com/public_html/login/edit_committee/edit.php on line 90
 
Notice: Undefined variable: imagepath in /home/sites/mydomain.com/public_html/login/edit_committee/edit.php on line 91
Which makes me think that the problem definately is a closed bracket and mostly like the one that is just above

Code: Select all

if(!get_magic_quotes_gpc())
For example, if I move it below the magic quotes section then the error regarding imagename and imagepath is no longer present. Therefore, I would think the logical place is at the bottom of the form with the other two closed brackets, but when I move it there, the page loads but without the form and no error messages. This is my current code with the closed bracket moved to the bottom of the script, just below the form. Is there any reason why it wouldn't work if it were at the end of the script?

Code: Select all

<?php
ini_set( "display_errors", 1 );
error_reporting( E_ALL );
include("../lib/config.php");
 
   $id = $_GET['id'];
 
   if(isset($_POST['submit']))
  {
 
      $member = $_POST['member'];
      $role = $_POST['role'];
      $sequence = $_POST['sequence'];
      
      if (isset ($_FILES['new_image']))
          {
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "../../images/committee_big/".$imagename;
              $member = $_POST['txtMember'];
              $role = $_POST['txtRole'];
              $sequence = $_POST['sequence'];
              move_uploaded_file($source, $target);
 
              $imagepath = $imagename;
              $save = "../../images/committee/" . $imagepath; //This is the new file you saving
              $file = "../../images/committee_big/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
 
              $modwidth = 150; 
 
              $diff = $width / $modwidth;
 
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
 
              imagejpeg($tn, $save, 100) ; 
 
              $save = "../../images/committee/" . $imagepath; //This is the new file you saving
              $file = "../../images/committee_big/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
 
              $modwidth = 80; 
 
              $diff = $width / $modwidth;
 
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
 
              imagejpeg($tn, $save, 100) ; 
              
if(!get_magic_quotes_gpc())
{
$imagename = addslashes($imagename);
$imagepath = addslashes($imagepath);
}
 
         $result = mysql_query("UPDATE committee SET member='$member', role='$role', sequence='$sequence' WHERE id='$id' ",$connect);
 
          echo "<b>Thank you! Committee Member UPDATED Successfully!<br />You'll be redirected to Home Page after (4) Seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
}
elseif($id)
{
 
        $result = mysql_query("SELECT * FROM committee WHERE id='$id' ",$connect);
        while($myrow = mysql_fetch_assoc($result))
             {
                $member = $myrow["member"];
                $role = $myrow["role"];
                $sequence = $myrow["sequence"];
?>
<h3>::Edit Committee Member</h3>
 
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<input type="hidden" name="id" value="<? echo $myrow['id']?>">
<tr>
<td>Member:</td><td><input name="member" size="40" maxlength="255" value="<? echo $member; ?>"></td></tr>
<tr>
<td>Role: </td><td><input name="role"  size="40" maxlength="255" value="<? echo $role; ?>" /></td></tr>
<tr>
<td>Order: </td><td><input name="sequence" size="40" maxlength="255" value="<? echo $sequence; ?>"></td></tr>
<tr>
<td>Image:</td><td><?php echo "<img src='../../images/committee/".$myrow['path']."'>"; ?></td>
</tr>
<tr>
<td>Add Image: </td><td><input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /><br /></td></tr>
<br />
</table><br />
<div align="center"><input type="submit" name="submit" value="Update Member"></div>
</form>
 
<?
}
              }
  }
  echo "<br /><a href=\"javascript&#058;self.history.back();\"><-- Go Back</a>";
?>