SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variable passed to each() is not an array or object

    Hi,

    I always got this error on my while list..
    Can anyone help with this..Really appreciate your hel

    Code PHP:
     
    <?php
    session_start();
    include_once("conn.php");
    if(isset( $_SESSION['username'])){
    $tick=$_GET['idno'];
    $new=mssql_fetch_assoc(mssql_query("Select * from  tblTicket  inner join tblAttachment 
    on tblTicket.TickNo=tblattachment.TicketNo inner join tblAssign on tblTicket.TickNo=tblAssign.TicketNo where tblTicket.TickNo='$tick'"));
    $img1=trim($new['image1']);
    $img2=trim($new['image2']);
    $img3=trim($new['image3']);
     ?>
    <!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" xml:lang="en-us">
    <head>
    <link href="css/mystyle.css" rel="stylesheet" type="text/css"/>	
    	<script src="jquery\jquery.min.js"></script>
    <script type="text/javascript" src="jquery\jquery.validate.js"></script> 
    <script>
    function textCounter(field, countfield, maxlimit)
    {
      if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
      else 
        countfield.value = maxlimit - field.value.length;
    }
    function textcount(field,mlimit)
    {
      field.value = field.value.substring(0, mlimit);
    }
    </script>
      <script>
      $(document).ready(function(){
        $("#newticket").validate({
    	  rules: {
    		msg:"required"
     
    	  }
     
    	});
      });
      </script>
    </head>
    <body onload="document.newticket.msg.focus();">
    <?php
     
    if(isset($_POST['Save'])){
     
    $ran=rand();
     
    while(list($key,$value) = each($_FILES["images"]["name"])){
    	if (($_FILES["images"]["size"][$key]))
    	{
     
    		$filename = $value;
    		$add = "upload/$filename";
     
    		$imagename=($_FILES['images']['name'][$key]);
    		$original_name=$filename;
    		if(!empty($value)) 
    		{ 
    		while(file_exists($add)){
    			$filename = rand().$original_name;
    			$add = "upload/".$filename;
    		}
    		if(copy($_FILES[images][tmp_name][$key],$add)){
    			chmod("$add",0777);
    		}
    		$i = $i+1;
    		$img[$i]=$filename;
    		}
    	}
    }
    	$image1=trim($img[1]);
    	$image2=trim($img[2]);
    	$image3=trim($img[3]);
    $msg=addslashes($_POST['msg']);
     
    	mssql_query("sp_post @tick='$_POST[id]',@msgby='$_SESSION[username]',@msg='".str_replace("'","''",$msg)."'");
    	mssql_query("sp_uploadfile @tickno='$_POST[id]',@createby='$_SESSION[username]',@createto='$new[UserName]',@img1='$image1',@img2='$image2',@img3='$image3'");
    }
     
    $usermsg=mssql_query("Select * from  tblForum   where TicketNo='$tick' order by Date desc");
    ?>
    <br/>
    <p>
    <table  border=1 bgcolor="white" width="100%" >
    <tr>
    	<td width="100%" align="left" valign="middle">
    	<img src='img/ticketprofile.png'>
    	</td>
    </tr>
    <tr>
    <td width="100%" align="left" >
    <table  align='center'>
     
    	<tr>
    		<td ><b>Ticket Number : </b><?php echo $new['TickNo']; ?></td>
    	</tr>
    	<tr>
    		<td ><b>Create By : </b><?php echo $new['UserName'];?>&nbsp; &nbsp;</td>
    		<td ><b>Assign to : </b><?php echo $_SESSION['username'];?></td>
    	</tr>	
    	<tr>
    		<td ><strong>Department : </strong><?php echo $new['Dept'];?>&nbsp; &nbsp;</td>
    		<td><strong>Email : </strong><?php echo $new['Email'];?></td>
    	</tr>
    	<tr>
    		<td ><strong>Date create : </strong><?php echo $new['DateCreate']." ".$new['TimeCreate'] ;?>&nbsp; &nbsp;</td>
    		<td><strong>Date Assign : </strong><?php echo $new['DateAssign'];?></td>
    	</tr>	
    	<tr>		
    		<td><strong>Category : </strong><?php echo $new['Category'];?>&nbsp; &nbsp;</td>
    		<td ><strong>Sub-Category : </strong><?php echo $new['Subcat'];?></td>
    	</tr>
    	<tr>
    		<td><strong>Description : </strong><?php echo $new['Description'];?></td>
    	</tr>
    	<tr>
    		<td><strong>File Attach : </strong>
     
    			<?php 
    				if(!empty($img1))
    				{
    				echo "<a href='DLfile.php?download_file=$new[image1]'>File 1</a> &nbsp";
    				}
    				if(!empty($img2))
    				{
    				echo "<a href='DLfile.php?download_file=$new[image2]'>File 2</a> &nbsp";
    				}
    				if(!empty($img3))
    				{
    				echo "<a href='DLfile.php?download_file=$new[image3]'>File 3</a> &nbsp";
    				}
    			?>
    		</td>
    	</tr>
     
    <tr>
    <td align='left'>
    <a href="#" onclick="document.getElementById('showattach').style.display=(document.getElementById('showattach').style.display== 'block')?'none':'block';">Attach a File</a>
    </td>
    </tr>
    <tr>
    <td align='left'>
    	<div  align='left' name='showattach' id='showattach' class='showattach' style="display: none"> 
     
     
    		<input align='left'  type='file' name='images[]'><br/>
     
    		<input align='left'  type='file' name='images[]' ><br/>
     
    		<input align='left'  type='file' name='images[]'>
    	</div>
    </td>
    </tr>	
    	</table>
    </td>
    </tr>	
    </p>	
    </table>
     
    <table align='center' width='70%'  >
     
    <?php while($row1=mssql_fetch_array($usermsg)){
    ?>
    	<tr align='left'> 
    		<td><?php echo "<font color='#ff0000' size='2'>".$row1['Date']."</font> "?></td>
    	</tr>	
    	<tr align='left'>
    		<td><b><?php echo $row1['MessageBy'].":";?></b>
    		<font color='#15317E'><?php echo  $row1['Message'];?></font></td>
    	</tr>	
    	<td><hr width='100%'></td>
     
    <?php
    }
    ?>
     
    </table>
    <form name='newticket' id='newticket' action='<?php $_SERVER['PHP_SELF'];?>' method='post' enctype="multipart/form-data">
    	<input type='hidden' name='id' value='<?php echo $tick;?>'>
    <table id='msgbox' name='msgbox' class='msgbox'  align='center' style='table-layout:fixed'>
     
    	 <col width=67>
     <col width=75>
     <col width=41>
    	<td align='left'valign=top><b>Message :</td>
    	<tr>
     
    		<td align='left'><textarea rows="10" cols="54" name="msg" wrap=physical onKeyDown="textCounter(this.form.msg,this.form.remLen,500);" onKeyUp="textCounter(this.form.msg,this.form.remLen,500);">
    		</textarea>
    		<br><input readonly type=text name=remLen size=3 maxlength=3 value="500"> characters left.</font></td>
    	</tr>
    	<tr>
    	<tr>
    	<td align='left'>
    		<input type='submit' value='Submit' name='Save'  onClick="javascript: var x=window.confirm('Send this message?');if (!x) return(false);">
    		<input type='Reset' value='Reset' name='reset'>
    	</td>
    	</tr>
    	</table>
    </form>
     
    </body>
    </html>
    <?php
    }else{ //not logged in
        header('location: login.php');
    }
    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I guess you're talking about this line?
    PHP Code:
    while(list($key,$value) = each($_FILES["images"]["name"])){ 
    Is $_FILES["images"]["name"] supposed to be an array?
    Do a var_dump($_FILES["images"]["name"]) to check.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the output is null..whether there is a value or none.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ryoka012 View Post
    the output is null..whether there is a value or none.
    If there's a value, var_dump wouldn't be null.

    Try var_dump($_FILES);

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the output is

    array(0) { }

    when i try var_dump($_FILES);

    i cant figure out what my error is.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Where exactly in your form do you select the file to upload?

  7. #7
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here..


    Code PHP:
    <td align='left'>
     
            <input align='left'  type='file' name='images[]'><br/>
     
            <input align='left'  type='file' name='images[]' ><br/>
     
            <input align='left'  type='file' name='images[]'>
        </div>
    </td>

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    That part of code is outside the form though, isn't it?

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    they are in the same form..it is hard to have to many form or page..so i decided to put them on the same page.

  10. #10
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah thanks i did not notice it..your right it is outside the form tag..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •