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
Handling an array, Radio button input, Writing to files
Old 02-26-2010, 07:32 PM Handling an array, Radio button input, Writing to files
Junior Talker

Posts: 2
Name: Lloyd
Trades: 0
This is my first time tackling php coding.

I'm trying to make an app that will allow a user to sort data uploaded from a file, and spit it out into 2 new files.

It can't be automated, because the human user needs to make the decision on where the data goes. Here's what I have so far

Code:
<body>

<?php

$file = '/public_html/temp/names.txt' or die('Could not read file!');
$data = file($file) or die('Could not read file!');

?> 

<?php

echo $data[0];
    
?>

<Form name ="form1" Method ="Post" ACTION ="nametool.php">
<Input type = 'Radio' Name ='choice' value= 'first'>first
<Input type = 'Radio' Name ='choice' value= 'last'>last
<Input type = 'Radio' Name ='choice' value= 'trash'>trash
<P>
<Input type = "Submit" Name = "Submit1" Value = "Select">
</P>
</FORM>


</body>
So I've got the radio buttons finished..and figured out how to parse the content from the file into an array.

What I'm confused about now is do I need the "isset" statement and how will the if/else tie in with that?

After a choice is made and the first item in the array is written to the sorted file it should delete that content and move to the next item in the array.

I read their was a way to do this (deleting one element in an array) last night but I'm unable to find it again. Something like a "push" statement?

Also I'm guessing my if/else statements will have to be nested?

If I can get this figured out it will save me a huge amount of time sorting data by cut and paste in a txt file. Thanks for any and all help.
Goody is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-26-2010, 08:04 PM Re: Handling an array, Radio button input, Writing to files
Junior Talker

Posts: 2
Name: Lloyd
Trades: 0
I forged ahead a bit farther, but getting an error now.


Code:
<body>

<?php

$file = '/public_html/temp/names.txt' or die('Could not read file!');
$data = file($file) or die('Could not read file!');

?> 

<?php

echo $data[0];
    
?>

<?php
if (!isset($_POST['Submit1'])) {
?>

<Form name ="form1" Method ="Post" ACTION ="nametool.php">
<Input type = 'Radio' Name ='choice' value= 'first'>first
<Input type = 'Radio' Name ='choice' value= 'last'>last
<Input type = 'Radio' Name ='choice' value= 'trash'>trash
<P>
<Input type = "Submit" Name = "Submit1" Value = "Select">
</P>
</FORM>

<?php
    }
else {
    
    $choice = $_POST['choice'];
    
    if ($choice = 'first') {
        echo 'chose option 1';
        }
    break;
    if ($choice = 'last') {
        echo 'chose option 2';
        }
    break;
    else {
        echo 'chose to throw away';
    }
}
?>


</body>
Parse error: syntax error, unexpected T_ELSE in /public_html/nametool.php on line 54
Goody is offline
Reply With Quote
View Public Profile
 
Old 02-26-2010, 10:23 PM Re: Handling an array, Radio button input, Writing to files
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You are using break incorrectly. The only time you should use break is in a switch statement. Also, == is used for comparison, = is used to set a value.
PHP Code:
else {
    
    
$choice $_POST['choice'];
    
    if (
$choice == 'first') {
        echo 
'chose option 1';
        }
    elseif (
$choice == 'last') {
        echo 
'chose option 2';
        }
    else {
        echo 
'chose to throw away';
    }

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-26-2010 at 10:25 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Handling an array, Radio button input, Writing to files
 

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.12782 seconds with 12 queries