Jump to content

Archived

This topic is now archived and is closed to further replies.

kolakube

Problems with creating a photo update page

Recommended Posts

Im very new to php and have tried to mess with this code I got from someone else, Im trying to create an update page for a very simple photo database, Im kinda stuck as I have been glaring over this the last few days and cant seems to see where im going wrong, I keep getting this error on line 121.

Warning: Invalid argument supplied for foreach() in ... line 121.
where I have
[code]
if (isset($_POST["op"]) && ($_POST["op"]=="UpdatePhoto"))
{

foreach ($_FILES["PHOTOONE"]["error"] as $key => $error)
            {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["PHOTOONE"]["tmp_name"][$key];
       $name = $_FILES["PHOTOONE"]["name"][$key];
       move_uploaded_file($tmp_name, "$ImagePath/".$_POST['PHOTOREF']."-$name");
$PHOTOONE = "".$_POST['PHOTOREF']."-$name";
                                }
            }
[/code]

can anyone please tell me what Im missing or am doing wrong, much appreciated, I put the whole page in just incase the problem is elsewhere.

[code]

<?php
include "config.php";
if (isset($_COOKIE["ValidUserAdmin"]))
{
?><HTML>
  <HEAD>
     <TITLE>Photo Album</TITLE> <LINK HREF="style.css" REL="stylesheet" TYPE="text/css">
     <style type="text/css">
<!--
.style1 {color: #FF0000}
-->
     </style>
</HEAD>
  <BODY><?PHP include "header.php"; ?>
     <TABLE WIDTH="760" ALIGN="CENTER" CLASS="maincentre">
        <TR>
          <TD>
             <P><B> EDIT</B><BR>
               <?php

if (isset($_POST["op"]) && ($_POST["op"]=="editphotoalbum"))
{

mysql_connect($server, $DBusername, $DBpassword) or die ("$DatabaseError - 42");
mysql_select_db($database);
$result = mysql_query("SELECT * from $photo_table where id = '".$_POST['id']."' LIMIT 1") or die ("$DatabaseError");

$row = mysql_fetch_array( $result );    
{
?>
               <br>
            </P>
            <form method="post" enctype="multipart/form-data">
<input name="id" type="hidden" value="<?php print "$row[id]"; ?>">
<input name="op" type="hidden" value="UpdatePhoto">


<br>

              <TABLE WIDTH="95%" border="0" ALIGN="CENTER" CELLPADDING="5" CELLSPACING="1" BGCOLOR="#f3f3f3">
<TR>
<TD width="165" BGCOLOR="#e1ebfb">
<P><b>Date:</b></P></TD>
<TD BGCOLOR="#f3f3f3">
<P> <?php print "$row[DATEADDED]"; ?></P></TD>
</TR>
<TR>
<TD width="165" BGCOLOR="#e1ebfb">
<P><b>Ref Number:</b></P></TD>
<TD BGCOLOR="#f3f3f3">
<P>
<strong><?php print "$row[PHOTOREF]"; ?></strong></P></TD>
</TR>

<TR>
<TD width="165" VALIGN="TOP" BGCOLOR="#e1ebfb">
<P><b>Long  Description:</b><BR>
<I>(HTML Permitted)</I></P></TD>
<TD BGCOLOR="#f3f3f3">
<P>
<TEXTAREA NAME="LONGDESCRIPTION" ROWS="15" COLS="65"><?php print "$row[LONGDESCRIPTION]"; ?></TEXTAREA>
</P></TD>
</TR>

<TR>
<TD width="165" BGCOLOR="#e1ebfb">
<P></P></TD>
<TD BGCOLOR="#f3f3f3">
<P> </P></TD>
</TR>
<TR>
<TD width="165" VALIGN="TOP" BGCOLOR="#e1ebfb">
<P><b>Upload Photos:</b><BR>
<I>(If no photo available leave blank for default image)</I></P></TD>
<TD BGCOLOR="#f3f3f3"><br></TD>
</TR>
<TR>
  <TD VALIGN="TOP" BGCOLOR="#e1ebfb">Picture 1:</TD>
  <TD BGCOLOR="#f3f3f3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><input name="PHOTOONE" type="file" size="35" ><br><?php print "$row[PHOTOONE]"; ?></td>
      </tr>
  </table></TD>
</TR>
<TR>
  <TD VALIGN="TOP" BGCOLOR="#e1ebfb">Picture 2: </TD>
  <TD BGCOLOR="#f3f3f3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><input name="TEMPPHOTOTWO" type="file" size="35" >
          <br>
        <?php print "$row[PHOTOTWO]"; ?></td>
      </tr>
  </table></TD>
</TR>
<TR>
  <TD VALIGN="TOP" BGCOLOR="#e1ebfb">Picture 3:</TD>
  <TD BGCOLOR="#f3f3f3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><input name="TEMPPHOTOTHREE" type="file" size="35" >
          <br>
          <?php print "$row[PHOTOTHREE]"; ?></td>
      </tr>
  </table></TD>
</TR>
<TR>
  <TD VALIGN="TOP" BGCOLOR="#e1ebfb">Picture 4:</TD>
  <TD BGCOLOR="#f3f3f3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><input name="TEMPPHOTOFOUR" type="file" size="35" >
          <br>
          <?php print "$row[PHOTOFOUR]"; ?></td>
      </tr>
  </table></TD>
</TR>
</TABLE>
<br>
<p align="center">  <input value="Update Photo Album" type="submit" class="submit" ONCLICK="return confirm('Are you sure you want to Update this Photo Album?');"></p>
          </form>
<br>

<?php
}

}
#### Update the requested photoalbum ####
if (isset($_POST["op"]) && ($_POST["op"]=="UpdatePhoto"))
{

foreach ($_FILES["PHOTOONE"]["error"] as $key => $error)
            {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["PHOTOONE"]["tmp_name"][$key];
       $name = $_FILES["PHOTOONE"]["name"][$key];
       move_uploaded_file($tmp_name, "$ImagePath/".$_POST['PHOTOREF']."-$name");
$PHOTOONE = "".$_POST['PHOTOREF']."-$name";
                                }
            }

foreach ($_FILES["PROPERTYHOTOTWO"]["error"] as $key => $error)
            {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["PHOTOTWO"]["tmp_name"][$key];
       $name = $_FILES["PHOTOTWO"]["name"][$key];
       move_uploaded_file($tmp_name, "$ImagePath/".$_POST['PHOTOREF']."-$name");
$PHOTOTWO = "".$_POST['PHOTOREF']."-$name";
                                }
            }
foreach ($_FILES["PHOTOTHREE"]["error"] as $key => $error)
            {        
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["PHOTOTHREE"]["tmp_name"][$key];
       $name = $_FILES["PHOTOTHREE"]["name"][$key];
       move_uploaded_file($tmp_name, "$ImagePath/".$_POST['PHOTOREF']."-$name");
$PHOTOTHREE = "".$_POST['PHOTOREF']."-$name";
                                }
            }
foreach ($_FILES["PHOTOFOUR"]["error"] as $key => $error)
            {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["PROPERTYPHOTOFOUR"]["tmp_name"][$key];
       $name = $_FILES["PHOTOFOUR"]["name"][$key];
       move_uploaded_file($tmp_name, "$ImagePath/".$_POST['PHOTOREF']."-$name");
$PHOTOFOUR = "".$_POST['PHOTOREF']."-$name";
                                }
            }


mysql_connect($server, $DBusername, $DBpassword) or die ("$DatabaseError - 42");
mysql_select_db($database);
mysql_query("UPDATE $photo_table SET
LONGDESCRIPTION = '$_POST[LONGDESCRIPTION]',
PHOTOONE = '$_POST[PHOTOONE]',
PHOTOTWO = '$_POST[PHOTOTWO]',
PHOTOTHREE = '$_POST[PHOTOTHREE]',
PHOTOFOUR = '$_POST[PHOTOFOUR]',
WHERE id = '$_POST[id]'");

print "<p align=\"center\"><font color=\"#CC0000\">Property details have been updated</font></p>";
print "<br><form method=\"post\">
<input name=\"op\" type=\"hidden\" value=\"editphotoalbum\">
<input name=\"id\" type=\"hidden\" value=\"".$_POST['id']."\">
<p align=\"center\"><input value=\"View New Details\" type=\"submit\" class=\"textinput\"></p>
</form>";

}
?>
          </TD>
        </TR>
     </TABLE><?PHP include "footer.php"; ?>
  </BODY>
</HTML>
<?php
}
   else
  {
    header("Location: login_error.php");
    exit;
  }
?>
[/code]

Share this post


Link to post
Share on other sites
Try this:
[code]foreach ($_FILES["PHOTOONE"] as $key => $error)
            {
   if ($error == UPLOAD_ERR_OK) {
       $tmp_name = $_FILES["PHOTOONE"]["tmp_name"][$key];
       $name = $_FILES["PHOTOONE"]["name"][$key];
       move_uploaded_file($tmp_name, "$ImagePath/".$_POST['PHOTOREF']."-$name");
$PHOTOONE = "".$_POST['PHOTOREF']."-$name";
                                }
            }[/code]

Share this post


Link to post
Share on other sites
Thanks for the quick reply, i have tried that just now, the error for that particular line seems to have disappeared, but Im still getting them for the next 3 below after I have omitted the ["Error'], and nothing was uploaded or updated with the photos.

any suggestions please [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Share this post


Link to post
Share on other sites

×

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.