r/PHPhelp • u/zephead98 • 5d ago
Solved Weird Echoing
So I have this script and when it gets to this point, it echos everything after $webuser=$db. I am completely stumped and claude just tells me there must be another "start php" somewhere in the $sSQL string. But there is not.
I will greatfully accept any and all input. (db is a database wrapper function that just connects to the db with the username and password).
//No errors on validation, insert/update record
if ($msgFormErr==""){
$sSQL="SELECT web_users_username, web_users_password, web_users_relid FROM webusers";
$webuser=$db->get_row($sSQL);
$username=$webuser->web_users_username;
$password=$webuser->web_users_password;
$webrelid=$webuser->web_users_relid;
$sSQL="SELECT studentcontact_email from studentcontact where studentcontact_id = $webrelid";
$email=$db->get_var($sSQL);};
?>
5
u/NumerousComplex1718 5d ago
by "it echos everything", you mean it's displaying the code instead of interpreting it? If so, make sure you have the <?php tag appropriately placed
8
u/flyingron 5d ago
Both the lines that start with $sqL="SELECT ...
do not have a closing ".
You might find it handy to use emacs, or PHPStorm, or some editor that colorizes the text that will call your attention to things like this.
3
u/ohnomybutt 5d ago
use a debugger.
1
u/zephead98 4d ago
I am going to mark this solved. Clearly I am not using all the available tools at my disposal, and our time will be better served by me taking a break, and installing and learning these tools.
I thank you all for your input! I am off to learn.
1
u/zephead98 1d ago
OK, so I want to kind of put this thread to bed. After hours of troubleshooting, I compared a similar file in this application to the one that was doing the weird echoing. The only difference I could find was the weird echoing one opened with the "short" php tag: <? whereas the other one opened with the better open tag: <?php . Changed to the better open tag and all problems went away. Now I will need to search all these files where php is started with the shortened tag, and this application has lots of mixed php and html, so it will be more than looking at the beginning of the file!
Thanks everyone for all the input. I have upgraded my developer station with VSCode and Xdebug, so I am making progress! So much to learn when you walk away from your code for 20 years!
1
u/ray_zhor 4d ago
Check your filename extension. If it's not .php. then that's your problem. Or check to see if there is a ? Before > where it starts to display
1
u/t1nkl 2d ago
php isnt running at all here. the browser gets your raw source, treats <?php ... as one tag and that "tag" ends at the first > it finds, which is the > in $db->. thats why everything after $webuser=$db shows up. check the file ends in .php and that you open it through the server (http://localhost/...) and not as a file or through a .html page. view source in the browser and you'll see the whole php code there
1
u/colshrapnel 4d ago
It's very simple. If you would open the page source (instead of staring at the rendered picture), as you always should as a backend developer, you will see entire code echoed out.