MadTechie Posted October 13, 2007 Share Posted October 13, 2007 Try this, if fails uncomment debug section <?php include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE Reciever='{$_SESSION['Current_User']}'") or die(mysql_error()); $row = mysql_fetch_assoc($GetLetters);//Moved for own formatting reasons if (!$row) { header("Location: letterbox.php"); die; }else{ $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; include("energybarinclude.php"); //Moved down (incase it un/sets $row) //DEBUGING Uncomment the 2 lines below if this fails #echo "MessageOne=$MessageOne<br>";//can remove this #print_r($row);//can remove this, $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'") or die(mysql_error()); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; } ?> <div id="bv_" style="position:absolute;left:375px;top:468px;width:224px;height:128px;z-index:19" align="center"> <font style="font-size:13px" color="#000000" face="Arial"><?= $MessageOne ?></font></div> <div id="bv_" style="position:absolute;left:182px;top:465px;width:150px;height:16px;z-index:22" align="left"> <font style="font-size:13px" color="#FFFFFF" face="Arial">Message:</font> </br> <font style="font-size:13px" color="#FFFFFF" face="Arial"><b>Subject: <?= $Subject ?><br> <br><br> From: <?=$From?> <br> Sent On:</br><?=$SentOn?> <br> <br> Reply!</b></font></div></body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-368812 Share on other sites More sharing options...
monkeybidz Posted October 14, 2007 Share Posted October 14, 2007 Remember that $_SESSION is superglobal, and can be read in all the script, but will not be worth anyhting in query. Thus not returning anything for that user, but will still echo by itself in the script. Have you tried this: $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever=".$_SESSION['Current_User'] ); ??? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369056 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Remember that $_SESSION is superglobal, and can be read in all the script, but will not be worth anyhting in query. Thus not returning anything for that user, but will still echo by itself in the script. What? That is no different to.... $GetLetters = mysql_query("SELECT * FROM messages WHERE Reciever='{$_SESSION['Current_User']}'"); Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369057 Share on other sites More sharing options...
monkeybidz Posted October 14, 2007 Share Posted October 14, 2007 How about if we spell receiver correctly in query? Is it the same in database? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369085 Share on other sites More sharing options...
thefollower Posted October 14, 2007 Author Share Posted October 14, 2007 Try this, if fails uncomment debug section <?php include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE Reciever='{$_SESSION['Current_User']}'") or die(mysql_error()); $row = mysql_fetch_assoc($GetLetters);//Moved for own formatting reasons if (!$row) { header("Location: letterbox.php"); die; }else{ $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; include("energybarinclude.php"); //Moved down (incase it un/sets $row) //DEBUGING Uncomment the 2 lines below if this fails #echo "MessageOne=$MessageOne<br>";//can remove this #print_r($row);//can remove this, $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'") or die(mysql_error()); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; } ?> <div id="bv_" style="position:absolute;left:375px;top:468px;width:224px;height:128px;z-index:19" align="center"> <font style="font-size:13px" color="#000000" face="Arial"><?= $MessageOne ?></font></div> <div id="bv_" style="position:absolute;left:182px;top:465px;width:150px;height:16px;z-index:22" align="left"> <font style="font-size:13px" color="#FFFFFF" face="Arial">Message:</font> </br> <font style="font-size:13px" color="#FFFFFF" face="Arial"><b>Subject: <?= $Subject ?><br> <br><br> From: <?=$From?> <br> Sent On:</br><?=$SentOn?> <br> <br> Reply!</b></font></div></body> </html> 50% of that works but the Username part does not... $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'") or die(mysql_error()); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; $From when echo'd contains a number which is correct and that is the sender's ID so now its just something to do with this small part of the script .. were nearly there No error occurs by the way. =/ Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369311 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Use.... <?php if (mysql_num_rows($FindUser1)) { $rowuser = mysql_fetch_assoc($FindUser1); print_($rowuser); die(); } else { die("No results match"); } ?> What do you get? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369313 Share on other sites More sharing options...
thefollower Posted October 14, 2007 Author Share Posted October 14, 2007 Fatal error: Call to undefined function print_() in C:\xampp\htdocs\readnewletters.php on line 26 What does that mean ? I think its cos print had a _ after it... when removed the result was: Array And that was it. Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369315 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Sorry, typo, should be... <?php if (mysql_num_rows($FindUser1)) { $rowuser = mysql_fetch_assoc($FindUser1); print_r($rowuser); die(); } else { die("No results match"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369317 Share on other sites More sharing options...
thefollower Posted October 14, 2007 Author Share Posted October 14, 2007 It shows the record that it finds: Array ( [userID] => 72 [username] => test ) Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369321 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Well there is your problem. Your field is Username not UserName. Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369323 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 <?php //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['Username']; //<-- update ?> EDIT: too slow, or thorpe's too quick! Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369324 Share on other sites More sharing options...
thefollower Posted October 14, 2007 Author Share Posted October 14, 2007 Damn it... something so little!! No wonder i didn't spot it, kept thinking it was a big problem than it actually was so i kept over looking it. Why doesn't it say "cannot find field" then seeing as its case sensitive ? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369327 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 i think it does if you add, to the start <?php // Report all PHP errors (bitwise 63 may be used in PHP 3) error_reporting(E_ALL); // Same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); ?> anyways.. is that solved ? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369328 Share on other sites More sharing options...
trq Posted October 14, 2007 Share Posted October 14, 2007 Why doesn't it say "cannot find field" then seeing as its case sensitive ? If you had error reporting and display errors on you would have gotten a notice trying to access a non existent array index. Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/page/2/#findComment-369329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.