Jump to content

Get method not finding the file


morrism35

Recommended Posts

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>

 

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 by benanamen
Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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">

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.