thefollower Posted October 12, 2007 Share Posted October 12, 2007 I have a code which is meant to load up the values from a SQL search yet when echo'd none appear even though the row in the database deffinatly exists =/ Cant figure out why... include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); if (!($row = mysql_fetch_assoc($GetLetters))) { header("Location: letterbox.php"); die; } Else{ include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'"); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/ Share on other sites More sharing options...
MadTechie Posted October 12, 2007 Share Posted October 12, 2007 <?php //This is wrong $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); //try this instead (also no session_start();?) $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='".$_SESSION['Current_User']."'"); include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender'];//Where is this being set ? (from the include are they correct?) ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368244 Share on other sites More sharing options...
teng84 Posted October 12, 2007 Share Posted October 12, 2007 <?php //This is wrong $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); //try this instead (also no session_start();?) $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='".$_SESSION['Current_User']."'"); include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender'];//Where is this being set ? (from the include are they correct?) ?> can you tell me why this is wrong $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); hmmm i know what you mean that it array issue but since the array index is not inclose with '' i believe it will work without error Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368246 Share on other sites More sharing options...
teng84 Posted October 12, 2007 Share Posted October 12, 2007 <? include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='".$_SESSION['Current_User']."'"); if (!$GetLetters ){ header("Location: letterbox.php"); exit(); } else{ include("energybarinclude.php"); $row = mysql_fetch_assoc($GetLetters); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'"); $rowuser = mysql_fetch_assoc($FindUser1); print_r($rowuser); echo 'netxquery<br>'; print_r($rowuser);//to check wether you fetch somthing try to check your queries Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368249 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 <?php //This is wrong $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); //try this instead (also no session_start();?) $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='".$_SESSION['Current_User']."'"); ?> Both of those are perfectly valid. I use the former all the time. http://www.php.net/manual/en/language.types.array.php#language.types.array.donts Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368250 Share on other sites More sharing options...
teng84 Posted October 12, 2007 Share Posted October 12, 2007 although i also said thats it is wrong its better to use the one with the dot IMO Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368258 Share on other sites More sharing options...
MmmVomit Posted October 13, 2007 Share Posted October 13, 2007 Try this instead. include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); $row = mysql_fetch_assoc($GetLetters) or die(mysql_error()); include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'"); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368270 Share on other sites More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 <?php //This is wrong $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='$_SESSION[Current_User]'"); //try this instead (also no session_start();?) $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='".$_SESSION['Current_User']."'"); ?> Both of those are perfectly valid. I use the former all the time. http://www.php.net/manual/en/language.types.array.php#language.types.array.donts Erm.. No they are NOT.. 1. $_SESSION[Current_User] will cause a notice error (as Current_User is not a Const but PHP will use the value as a string), it works but is bad pratice.. 2. an array can not be used in a sting unless it escape but {} or concatenated ie "test".array['blar']."er") please review the referance you posted. Why is $foo[bar] wrong? You should always use quotes around a string literal array index. For example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong? You might have seen the following syntax in old scripts: and // This will not work, results in a parse error such as: // Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING' // This of course applies to using superglobals in strings as well print "Hello $arr['fruit']"; Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368284 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 @madtechi IMO '$teng[astig]' <-- valid '$teng['astig']' or '$teng["astig"]'<--invalid and yah better to use dots or concatenate Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368295 Share on other sites More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 <?php //invalid echo "test ".$teng[astig]; //but will work, but bad pratice echo "test $teng['astig']"; //valid echo "test ".$teng['astig']; echo "test {$teng["astig"]}"; echo "test {$teng['astig']}"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368301 Share on other sites More sharing options...
teng84 Posted October 13, 2007 Share Posted October 13, 2007 yah i know its just that we are refering to the error of this tread and you site that part wich i think it doesnt solve the issue any way and any how LISTEN to madtechi <?php //invalid echo "test ".$teng[astig]; //but will work, but bad pratice echo "test $teng['astig']"; //valid echo "test ".$teng['astig']; echo "test {$teng["astig"]}"; echo "test {$teng['astig']}"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368304 Share on other sites More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 also need to findout $From = $row['Sender'];//Where is this being set ? (from the include are they correct?) think we need to wait for a post back lol i think this should give some insight! <?php include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='{$_SESSION['Current_User']}'") or die(mysql_error()); if (!($row = mysql_fetch_assoc($GetLetters))) { header("Location: letterbox.php"); die; } Else{ include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368320 Share on other sites More sharing options...
trq Posted October 13, 2007 Share Posted October 13, 2007 Its being set here... if (!($row = mysql_fetch_assoc($GetLetters))) { Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368348 Share on other sites More sharing options...
monkeybidz Posted October 13, 2007 Share Posted October 13, 2007 I did not see in the original post where you actually define $row, but yet you are stating that $Subject=$row['Subject']; What row? Try this. include("include.php"); $current_user=$_SESSION['Current_User']; $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever=$current_user "); $row=mysql_fetch_assoc($GetLetters); if (!$row) { header("Location: letterbox.php"); die; } Else{ include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'"); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368351 Share on other sites More sharing options...
trq Posted October 13, 2007 Share Posted October 13, 2007 I repeat, it is set here.... if (!($row = mysql_fetch_assoc($GetLetters))) { Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368354 Share on other sites More sharing options...
trq Posted October 13, 2007 Share Posted October 13, 2007 I don't see where you actually echo anything. Can we see your actual and current code? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368356 Share on other sites More sharing options...
MadTechie Posted October 13, 2007 Share Posted October 13, 2007 i think we need to way for some more feed back from thefollower, i'll admit i missed the row being set but as i said, this should give us some better feedback <?php include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE reciever='{$_SESSION['Current_User']}'") or die(mysql_error()); if (!($row = mysql_fetch_assoc($GetLetters))) { header("Location: letterbox.php"); die; } Else{ include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368357 Share on other sites More sharing options...
thefollower Posted October 13, 2007 Author Share Posted October 13, 2007 MadTechie i just put your code and no values are echo'd To answer your question earlier current_user is in my include its global, and is created as the user logs in. And it does 100% work otherwise it wouldn't allow me to access the page as i have put validation to log me out if there was a problem with it in the global include. My echo's use short tags <?=$blah?> and yes they are turned on in my apache. This is the code at current + echo's: <? include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE Reciever='{$_SESSION['Current_User']}'") or die(mysql_error()); if (!($row = mysql_fetch_assoc($GetLetters))) { header("Location: letterbox.php"); die; } Else{ include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $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> Just to add, no errors occur, but it must be finding the row otherwise it would take me to the header("location: letterbox.php"); page. I am wondering could the second include cause a problem if theres a header before it ? =/ Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368581 Share on other sites More sharing options...
esukf Posted October 13, 2007 Share Posted October 13, 2007 Try :- <?php include("include.php"); $GetLetters = mysql_query("SELECT * FROM messages WHERE Reciever='{$_SESSION['Current_User']}'") or die(mysql_error()); if (mysql_num_rows($GetLetters) == 0) { header("Location: letterbox.php"); exit; } else { include("energybarinclude.php"); $row = mysql_fetch_assoc($GetLetters); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $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']; } ?> You might want to use a JOIN instead of using another query to get the username <?php $GetLetters = mysql_query("SELECT UserID, Subject, Sender, Senttime, MessageText FROM messages INNER JOIN userregistration ON (messages.sender = userregistration.UserID) WHERE Reciever = '{$_SESSION['Current_User']}'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368588 Share on other sites More sharing options...
monkeybidz Posted October 13, 2007 Share Posted October 13, 2007 $row=mysql_fetch_assoc($GetLetters); //Setting $row if(!$row = mysql_fetch_assoc($getLetters)) { //Checking if $row is false I did not see $row as defined or set since you used "!" in front if it. if (!($row = mysql_fetch_assoc($GetLetters))) { like if false or empty $row go to letterbox page? Your just asking and not setting with the if(! this is why you don't get a variable return echoed. Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368603 Share on other sites More sharing options...
thefollower Posted October 13, 2007 Author Share Posted October 13, 2007 I cannot do the inner join because the Sender is up via ID but im trying to Echo the name of the user not the ID.. so it would have to be a separate sql query .. right? Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368605 Share on other sites More sharing options...
thefollower Posted October 13, 2007 Author Share Posted October 13, 2007 $row=mysql_fetch_assoc($GetLetters); //Setting $row if(!$row = mysql_fetch_assoc($getLetters)) { //Checking if $row is false I did not see $row as defined or set since you used "!" in front if it. if (!($row = mysql_fetch_assoc($GetLetters))) { like if false or empty $row go to letterbox page? Your just asking and not setting with the if(! this is why you don't get a variable return echoed. try testing it i can assure ya it does set it Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368610 Share on other sites More sharing options...
monkeybidz Posted October 13, 2007 Share Posted October 13, 2007 I think i got it! Do not Capitalize Else Not valid This is why you get no echo. I would try this anyways include("include.php"); $GetLetters = mysql_query("SELECT * FROM `messages` WHERE `reciever`='$_SESSION[Current_User]' AND `Subject`=Subject AND `Senttime`=Senttime AND `MessageText`=MessageText "); $row=mysql_fetch_array(mysql_query($GetLetters)); if (!$row) { header("Location: letterbox.php"); die; } else{ include("energybarinclude.php"); $Subject = $row['Subject']; $From = $row['Sender']; $SentOn = $row['Senttime']; $MessageOne = $row['MessageText']; $FindUser1 = mysql_query("SELECT * FROM userregistration WHERE UserID='$From'"); //Fetch the row from the database $rowuser = mysql_fetch_assoc($FindUser1); $UserName1 = $rowuser['UserName']; $_SESSION['Current_User'] Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368622 Share on other sites More sharing options...
esukf Posted October 13, 2007 Share Posted October 13, 2007 I cannot do the inner join because the Sender is up via ID but im trying to Echo the name of the user not the ID.. so it would have to be a separate sql query .. right? You can grab what ever column you want once the tables are joined. <?php $GetLetters = mysql_query("SELECT Username, Subject, Sender, Senttime, MessageText FROM messages INNER JOIN userregistration ON (messages.sender = userregistration.UserID) WHERE Reciever = '{$_SESSION['Current_User']}'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368633 Share on other sites More sharing options...
thefollower Posted October 13, 2007 Author Share Posted October 13, 2007 ok i tried the non capital e but made no difference with the else... it does run throufh the else as i put : echo 'bwfsffsdfsd'; and it echo'd , ive never seen php be fussy over a capital E for else before... all my scripts have capital E and they work fine =/ Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\readnewletters.php on line 5 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\readnewletters.php:5) in C:\xampp\htdocs\readnewletters.php on line 7 It won't allow the header for some reason even though your code has it encased in a if statement =/ Referring to monkeybidz's code. Quote Link to comment https://forums.phpfreaks.com/topic/73009-solved-variables-have-no-values-when-echod/#findComment-368634 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.