Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Loading txt after submit button clicked
Old 02-09-2009, 12:12 AM Loading txt after submit button clicked
Junior Talker

Posts: 4
Trades: 0
Hey,

I'm working on a page that has a drop down menu dynamically built using data from a csv file. The csv file holds the filename & the description of a page.
The form is in the first cell of a table. I want to load the selected file text into the 2nd cell when the user clicks submit...
I am having a problem. It creates the dropdown menu without a problem.
When i click submit, it just reloads the same page, and resets the dropdown menu.
I'm not sure where my code is wrong.
Any suggestions??

Code:
 
<?php
#session_start(); 
$fh = fopen("inc/rant.inc","r")                    #has the filename & description
 or die ("File Not Found");
 while (!feof($fh))
 {
    $line[] = fgetcsv($fh);       
 }
fclose($fh);
 
if ($_POST)
{
 
//get the rant page they selected
$rantFileName = 'rant/'. $_Post["rantSelect"];
echo $rantFileName;
echo "<pre>";
print_r($_Post);
echo "</pre>";
 
 $fh2 = fopen("inc/rant.inc","r")
  or die ("Rant File Not Found");
  while (!feof($fh2))
  {
      $rantText = file_get_contents($fh2);
  }
 fclose($fh);
}
 
?>
<table align="left" cellpadding="2" cellspacing="2" border="2"  >
  <tr>
     <td>
    <FORM METHOD=post ACTION="rant.php">
            <CENTER>
            Select an rant:
    <SELECT id="rantSelect">
    <option id="empty">"Select the rant you want to read."</option>;
       <?php
            foreach($line as $record)   #this loads the array into the dropdown
              {
      $list = '<option id="'. $record[0] .'"';
                              if ($record[0] == $rantFileName)
                              {
                               $list .= ' selected ';
                              }
                              $list .= '>"'. $record[1] .'</option>';
      echo $list;
#                  echo $record[0] . " - " . $record[1] . "<br />";
             }
            ?>
            </SELECT><BR>
            <INPUT type="Submit" VALUE="Submit"   ></CENTER>
            </FORM>
    </td>
    <td>
       <? echo $rantText; ?>
 
    <!-- this is where it'll load the rant page that was selected. -->
    </td>
 </tr>
</table
<hr>
myrrdan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-09-2009, 08:50 AM Re: Loading txt after submit button clicked
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Your <option>'s don't have a value.
I think you're trying to use id for that purpose, but that isn't possible.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-09-2009, 12:34 PM Re: Loading txt after submit button clicked
Junior Talker

Posts: 4
Trades: 0
hmmmm. ok
I think i get what you mean, except that the dropdown menu does load the file info into it.
the <option id> = "file description" does populate the dropdown menu...
so if i change that to option value> ... would it then populate it & select it correctly?
myrrdan is offline
Reply With Quote
View Public Profile
 
Old 02-09-2009, 01:04 PM Re: Loading txt after submit button clicked
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
Hmm, I didn't know ID was working as well.
Then that is not your problem.

I see now though, that you are doing something rather weird.
PHP Code:
$fh2 fopen("inc/rant.inc","r")
  or die (
"Rant File Not Found");
  while (!
feof($fh2))
  {
      
$rantText file_get_contents($fh2);
  }
 
fclose($fh); 
What you're doing is opening a file handler to a file.
Then while the pointer hasn't reached the end of the file on that handler, you try to read the whole file into a string by supplying file_get_contents with a file handler, but you should supply the filename.
This bit could just be replaced by:

PHP Code:
if(file_exists("inc/rant.inc")){
      
$rantText file_get_contents("inc/rant.inc");
}else{
      echo 
"File not found!";

__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-09-2009, 01:08 PM Re: Loading txt after submit button clicked
Junior Talker

Posts: 4
Trades: 0
yep i see what you mean, my problem is that the file name will be different depending on what they selected.
and its a dynamic list, will change as I add new rant files...
but i think i still see the problem.. its loading the wrong file i think..

i'll have to take a closer look...
myrrdan is offline
Reply With Quote
View Public Profile
 
Old 02-09-2009, 01:39 PM Re: Loading txt after submit button clicked
Junior Talker

Posts: 4
Trades: 0
lol fixed it
it did need to be value instead of Id
and the first option id line, that needed to be option name
once i did those.. it works
thanks for your suggestion about the value... it helped me catch the name
myrrdan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Loading txt after submit button clicked
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16876 seconds with 12 queries