morrism35 Posted October 22, 2015 Share Posted October 22, 2015 I have ran every combination for a value for my source_file but nothing is allowing my isset($_GET) to execute. The file runs but it only executes the else statement. This is code directly out of my text book for a Chinese Zodiac Discovery Project. <?php if(isset($_GET['source_file'])){ $SourceFile = file_get_contents( stripslashes($_GET['source_file'])); highlight_string($SourceFile); } else echo "<p>No source file name entered</p>\n"; ?> ___________________________________________________________ <div id-"string"> <a id="string">String Functions</a> <p>This script counts the number of times each letter appears in a string andcompares that count to the number of times </p> <a href="SimiliarNames.php">Test Similiar Names Script</a> //Source file <a href="ShowSourceCode.php"? source_file=SimiliarNames">[View the Source Code]</a> </div> <div id="char"> <a id="char">Character Functions</a> <p>This script finds the number of words embedded</p> <a href="EmbeddedWords.php">Test EmbeddedWords Script</a> //Source file <a href="ShowSourceCode.php"?source_file=EmbeddedWords">[View the Source Code]</a> </div> Quote Link to comment Share on other sites More sharing options...
iarp Posted October 22, 2015 Share Posted October 22, 2015 You might want to have a look at what the following code outputs, I highly doubt it's doing what you think it's doing. echo stripslashes($_GET['source_file']); Quote Link to comment Share on other sites More sharing options...
morrism35 Posted October 22, 2015 Author Share Posted October 22, 2015 It is supposed to output the source code of the file the I send to the get method with the highlights(caused by highlight_string) Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 22, 2015 Share Posted October 22, 2015 Because your links are wrong <a href="ShowSourceCode.php"? source_file=SimiliarNames">[View the Source Code]</a> ... <a href="ShowSourceCode.php"?source_file=EmbeddedWords">[View the Source Code]</a> Your links will not be passing the querystring to ShowSourceCode.php, it needs to be within the href attribute. <a href="ShowSourceCode.php?source_file=SimiliarNames.php">[View the Source Code]</a> ... <a href="ShowSourceCode.php?source_file=EmbeddedWords.php">[View the Source Code]</a> Quote Link to comment Share on other sites More sharing options...
morrism35 Posted October 22, 2015 Author Share Posted October 22, 2015 Thank you, the no source found message is going but it just outputs a blank page. Everything looks like it should read my source_file and execute but still not sure why it's not outputting the source code for the file that I send it. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 22, 2015 Share Posted October 22, 2015 You need to use echo before highlight_string if you want to output the source code with syntax highlighting echo highlight_string($SourceFile); Quote Link to comment Share on other sites More sharing options...
morrism35 Posted October 22, 2015 Author Share Posted October 22, 2015 Thanks but that only outputs a 1 when I click on the file. the code out of the book doesn't have a echo with that highlight statement. Could be bad code in the book. It's called PHP programming with mysql by Don Gossein. 90% of the reviews that I have read on Amazon have been very bad about this book, but that's what my MIA(no classmate has heard from him in a month) instructor wants us to use. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 22, 2015 Share Posted October 22, 2015 Turn on error checking to see if something is wrong with your script. See my signature. Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 22, 2015 Share Posted October 22, 2015 (edited) This works.... <!DOCTYPE html> <html> <head> <title>Hello!</title> </head> <body> <?php if(isset($_GET['source_file'])){ $SourceFile = file_get_contents( stripslashes($_GET['source_file'])); highlight_string($SourceFile); } else{ echo "<p>No source file name entered</p>\n"; } ?> ___________________________________________________________ <div id-"string"> <a id="string">String Functions</a> <p>This script counts the number of times each letter appears in a string andcompares that count to the number of times</p> <a href="SimiliarNames.php">Test Similiar Names Script</a> //Source file <a href="ShowSourceCode.php?source_file=ShowSourceCode.php">[View the Source Code]</a> </div> <div id="char"> <a id="char">Character Functions</a> <p>This script finds the number of words embedded</p> <a href="EmbeddedWords.php">Test EmbeddedWords Script</a> //Source file <a href="ShowSourceCode.php?source_file=ShowSourceCode.php">[View the Source Code]</a> </div> </body> </html> Edited October 22, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
morrism35 Posted October 22, 2015 Author Share Posted October 22, 2015 This needs to be at the top of all php coded pages. I'm only on the 5th chapter of the book, i've never heard of this. Should this be in a php tag. And is this the correct code: error_reporting(E_ALL); ini_set('display_errors', '1'); error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 22, 2015 Share Posted October 22, 2015 Except you mixed your html and php code together. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 22, 2015 Share Posted October 22, 2015 Yes - it is php code and s/b at the top along with all of your php code (and not your html) whenever you are developing your scripts. Quote Link to comment Share on other sites More sharing options...
morrism35 Posted October 22, 2015 Author Share Posted October 22, 2015 Hey guys and girls I got it. Can't believe it was a simple file name on my web server that was wrong. Think I'm just burning out with php. I'm finding this language much more difficult to learn than java or C++. Not sure why. Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 22, 2015 Share Posted October 22, 2015 Except you mixed your html and php code together. Normally it would go above the html, but in this case, it needs to be where it is for the page to validate. OP, just noticed a couple problems. You cannot use the same id name more than once in a page. You have done it twice. Also this should have an = sign <div id-"string"> Quote Link to comment Share on other sites More sharing options...
morrism35 Posted October 22, 2015 Author Share Posted October 22, 2015 Supposed to be an internal link and I just wrote it on this message board just to make things easier for everyone to see. In my program it is a seperate file. I'm really am not very strong in html. I took that course about a yr ago and it's really hurt my progress in php. My programming curriculum for my associates degree took me through a wide variety of computer languages so I really haven't had a chance to get a good grip on one language. Quote Link to comment 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.