Page 1 of 1

lost array information?

Posted: Tue Jan 27, 2004 6:20 pm
by m3rajk
i think my brain went on vacation and forgot to inform me. i can't find any error here, yet the information in the display side.. the information retrieved from the db, not all of it is not being displayed... the issue here is that it USED to work anf that i know those feilds exist AND have information (from checking the db directly)

for some reason the information fromt he fetch array is blank

any hints as to what i'm doing wrong will be greatly appreciated

Code: Select all

}else{ # it's ok to let you write a message, or to send it
        if(isset($_POST['message'])){ # we're sending a site message
          $message=clean($_POST['message']); # get rid of "bad" characters
          $sendmsg=mysql_query("INSERT INTO msgs (to_id, from_id, from_un, sent, message) VALUES ('$toid', '$uid', '$un', NOW(), '$message')", $db); 
          if(mysql_affected_rows($db)){ # it was sent
            bgnmsgpg('Site Message Sent');
            echo "<p>Message Sent to $to<br />Click <a href="3" onclick="window.close();">here</a> to close this window</p>";
            clspg();
          }
        }else{ # set up the message interface
          $msg1=''; $msg2=''; $when='';
          if(isset($_GET['mid'])){ # there is a sent message
            $mid=$_GET['mid'];  # message id number
            $frmsginf=mysql_query("SELECT message,from_un,from_id,UNIX_TIMESTAMP(sent) FROM msgs WHERE msg_id='$mid' AND to_id='$toid'", $db); # only the person it's sent TO may see
            $msginf=mysql_fetch_array($frmsginf);  # message info
            $vmsg=mysql_query("UPDATE msgs SET viewed='1' WHERE msg_id='$mid'", $db); # set to viewed
            $when="Message Sent At: ".gmdate($utds, ($msginf['UNIX_TIMESTAMP(sent)']+($gmto*60*60)));  # when was it sent? (get the unix timestamp of the time from mysql, add the gmt offset, in seconds, and format the way the user wants to see the dates)
            $pto=strtolower($msginf['from_un']); # name lowercase for the pictures
            $msg1='       <tr><td colspan="5">'.codeparse($msginf['message']).'</td></tr>'; # message to show the user
            $msg2="[quote=$to]{$msginf['message']}[/quote]"; # reply box
          }
          bgnmsgpg('Reading/Sending FYDim'); # start the page
          // this heredoc creates the body
          echo <<<END
    <form action="{$_SERVER['PHP_SELF']}" method="POST" onReset="window.close();">
      <input id="to" name="to" type="hidden" value="$to">
      $tsnwb1
        <tbody>
          <tr>
            <td rowspan="3" class="smthmb"><a href="profile.php?un={$msginf['from_un']}" target="profile"><img alt="{$msginf
['from_un']}" class="smthmb" src="pic.php?pic=main.$pto.jpg&fn=ltn" /></a></td>
            <td colspan="2">Message To/From: <a href="profile.php?un={$msginf['from_un']}" target="profile">$to</a></td>
            <td colspan="2"><a href="block.php?pest={$msginf['from_un']}" target="_self">Block User</a></td>
          </tr>
          <tr>
            <td colspan="3">$when</td>
            <td ><a href="code.php" target="code">SiteCode</a> On</td>
          </tr>
          <tr>
            <td><input type="submit" value="Send Mail" /></td>
            <td><input type="reset" value="Close Window" /></td>
            <td colspan="2"><a name="#desire" href="#desire" onclick="window.open('adddesire.php?fun={$msginf['from_un']}&fu
in=$toid', 'desire', 'height=196,width=288');">Add Desire</a></td>
          </tr>
$msg1
          <tr>
            <td colspan="5"><textarea cols="59" id="message" name="message" rows="5">$msg2</textarea></td>
          </tr>
        </tbody>
      </table>
    </form>
END;
          clspg(); # close the page
        }
thanx in advance, josh

Posted: Tue Jan 27, 2004 8:45 pm
by m3rajk
the host it's erroring on:
PHP4 scripting (version 4.3.3 currently)
current MySQL version is: 4.0.16-standard

host it works perfectly on:
php 4.2.2
mysql 3.23.58

Posted: Tue Jan 27, 2004 10:08 pm
by m3rajk
on second look i'm not sure how it's getting the return name on the deployment server, because the rest of the information is not there.

Posted: Wed Jan 28, 2004 5:42 pm
by m3rajk
changing the line
$msginf=mysql_fetch_array($frmsginf);
to
$msginf=mysql_fetch_array($frmsginf);
foreach($msginf as $key=>$value){ echo "<p>key: $key ---> value: $value</p>"; }
gets the error:
Warning: Invalid argument supplied for foreach() in /home/dcfydllc/www/message.php on line 33
which tells me that there's an issue with the mysql_fetch_array call. (line 32)

Posted: Wed Jan 28, 2004 6:35 pm
by John Cartwright
I havn't really looked through your code but try echo'ing your variables to see if they are blank

Posted: Thu Jan 29, 2004 12:57 pm
by m3rajk
i tried debugging by setting a variable for the sql line, then echoing that out after the line where i make the select command and then use mysql_errno and mysql_error to find out the errors. it's exactly what i expect for hte sql command and without any errors.

no errors after mysql_fetch_array() either, yet nothing in the array. nothing if i swithc ot myswl_fetch_assoc either

Posted: Thu Jan 29, 2004 9:51 pm
by m3rajk
well... here's with debugging lines...

Code: Select all

[dcfydllc@seed www]$ cat message.php 
<?php
include("/home/dcfydllc/includes/fyd.incs.php"); # includes file
$un=$_COOKIE['un']; $pw=$_COOKIE['pw']; $to=''; $gmto=$_COOKIE['gmto']; $utds=$_COOKIE['utds'];
if(isset($_POST['to'])){ $to=$_POST['to']; }else{ $to=$_GET['to']; }

$db=mysql_connect($host, $login2, $pass2) or die("cannot access mysql"); # connect to the db
$fyd=mysql_select_db($dbname, $db) or die("cannot access db"); # get the db
$toinf=mysql_query("SELECT uid,msgs FROM users WHERE username='$to'", $db);
if(mysql_num_rows($toinf)){ # we found the user
  $getto=mysql_fetch_array($toinf); $toid=$getto['uid']; $msgs=$getto['msgs'];
  if($msgs){ # they accept ims
    $verify=mysql_query("SELECT uid FROM users WHERE username='$un' AND password='$pw'", $db);
    if(mysql_num_rows($verify)){ # user is verified
      $getuid=mysql_fetch_array($verify); $uid=$getuid['uid']; # who is this?
      $checkblock=mysql_query("SELECT pun FROM pests WHERE uid='$toid' AND puid='$uid'", $db);
      if(mysql_num_rows($checkblock)){ # user has blocked you
        bgnmsgpg('BLOCKED'); echo "<h1>$to has blocked you</h1>"; clspg();
      }else{ # it's ok to let you write a message, or to send it
        if(isset($_POST['message'])){ # we're sending a site message
          $message=clean($_POST['message']);
          $sendmsg=mysql_query("INSERT INTO msgs (to_id, from_id, from_un, sent, message) VALUES ('$toid', '$uid', '$un', NOW(), '$message')", $db);
          if(mysql_affected_rows($db)){ # it was sent
            bgnmsgpg('Site Message Sent');
            echo "<p>Message Sent to $to<br />Click <a href="3" onclick="window.close();">here</a> to close this window</p>";
            clspg();
          }
        }else{ # set up the message interface
          $msg1=''; $msg2=''; $when=''; $debug='';
          if(isset($_GET['mid'])){ # there is a sent message
            $mid=$_GET['mid']; # what message number is this?
            $sql="SELECT message,from_un,from_id,UNIX_TIMESTAMP(sent) FROM msgs WHERE msg_id='$mid' AND to_id='$toid';"; # sql query
            $frmsginf=mysql_query($sql, $db); # only the person it's sent TO may see
            $debug.="<p>sql: $sql<br>frmsginf: $frmsginf<br>error: ".mysql_errno($db).': '.mysql_error($db);
            $msginf=mysql_fetch_array($frmsginf); 
            $debug.="<br>msginf $msginf<br>error: ".mysql_errno($db).': '.mysql_error($db).'</p>';
            $vmsg=mysql_query("UPDATE msgs SET viewed='1' WHERE msg_id='$mid'", $db);
            $when="Message Sent At: ".gmdate($utds, ($msginf['UNIX_TIMESTAMP(sent)']+($gmto*60*60))); 
            $pto=strtolower($msginf['from_un']);
            $msg1='       <tr><td colspan="5">'.codeparse($msginf['message']).'</td></tr>';
            $msg2="[quote=$to]{$msginf['message']}[/quote]";
          }
          bgnmsgpg('Reading/Sending FYDim');
          echo <<<END
$debug
    <form action="{$_SERVER['PHP_SELF']}" method="POST" onReset="window.close();">
      <input id="to" name="to" type="hidden" value="$to">
      $tsnwb1
        <tbody>
          <tr>
            <td rowspan="3" class="smthmb"><a href="profile.php?un={$msginf['from_un']}" target="profile"><img alt="{$msginf['from_un']}" class="smthmb" src="pic.php?pic=main.$pto.jpg&fn=ltn" /></a></td>
            <td colspan="2">Message To/From: <a href="profile.php?un={$msginf['from_un']}" target="profile">$to</a></td>
            <td colspan="2"><a href="block.php?pest={$msginf['from_un']}" target="_self">Block User</a></td>
          </tr>
          <tr>
            <td colspan="3">$when</td>
            <td ><a href="code.php" target="code">SiteCode</a> On</td>
          </tr>
          <tr>
            <td><input type="submit" value="Send Mail" /></td>
            <td><input type="reset" value="Close Window" /></td>
            <td colspan="2"><a name="#desire" href="#desire" onclick="window.open('adddesire.php?fun={$msginf['from_un']}&fuin=$toid', 'desire', 'height=196,width=288');">Add Desire</a></td>
          </tr>
$msg1
          <tr>
            <td colspan="5"><textarea cols="59" id="message" name="message" rows="5">$msg2</textarea></td>
          </tr>
        </tbody>
      </table>
    </form>
END;
          clspg();
        }
      }
    }else{ # un/pw don't match
      bgnmsgpg('verification failure'); 
      echo '<p>Verification failure. Please make sure you are <a href="login.php">Logged In</a></p>';
      clspg();
    }
  }else{ # the user has ims turned off
    bgnmsgpg("$to does not accept site messages"); echo "<p>$to has site messaging turned off</p>"; clspg();
  }
}else{ # no user
  bgnmsgpg("Error sending sitemail to $to");
  echo '<p>Unable to find user in database. Please try back later</p>';
  clspg();
}
?>[dcfydllc@seed www]$
and the result
sql: SELECT message,from_un,from_id,UNIX_TIMESTAMP(sent) FROM msgs WHERE msg_id='1' AND to_id='47';
frmsginf: Resource id #10
error: 0:
msginf
error: 0:

Posted: Thu Jan 29, 2004 10:20 pm
by m3rajk
never mind, i figured it out

Posted: Tue Feb 17, 2004 12:39 pm
by StudlyDego73
m3rajk-

I'm having a similar problem. I get an error with my mysql_fetch_array() call though on another machine it works perfectly fine. The machine it's erroring on is also a php 4.3.3 and mysql 4.0.16. I was wondering if you could tell me what you did to fix your problem. Any help would be greatly appreciated. Thanks!