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
Old 05-11-2009, 09:08 PM PHP text write
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
OK, I got this homework assignment to do in php, I'm supposed to add to this code that they give me in the book.... strangely enough the code doesn't even work or I copied it wrong... either way, I can't spot the error and im going mad. Everything works except when I get to writing the file... It's due in a few hours, so the faster i receive help the faster my stress level goes down. :P
Thanks.

SendingRSVP.php
Code:
<html>
  <head>
    <title>RSVP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>

<?php

if (empty($_GET['name']) || !isset($_GET['attendance']))
    echo "<p>You must enter your name and specify whether you will attend! Click your browser's Back button to return to the RSVP form.</p>";

else
    if($_GET['attendance'] == "yes" && !is_numeric($_GET['guests']))
        echo "<p>Please specify the number of guests who will accompany to the RSVP form.</p>";
    

else {
    if($_GET['attendance'] == "yes") {
        $YesFile = "attending.txt";
        
            if(file_put_contents($YesFile, addslashes($_GET['name']) . ", " . $_GET['guests'] . "\n", FILE_APPEND))
                echo "<p>Thanks for RSVP'ing! We're looking forward to seeing you!</p>";
            

else
    echo "<p>Cannot save to the $YesFile file.</p>";
    }

if($_GET['attendance'] == "no") {
    $NoFile = "notattending.txt";
    
    if(file_put_contents($NoFile, addslashes($_GET['name']) . "\n", FILE_APPEND))
        echo "<p>Thanks for RSVP'ing! Sorry you can't make it!</p>";

        else
            echo "<p>Cannot save to the $NoFile file.</p>";
 }
}
?>
</body>
</html>
RSVP.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>RSVP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <h1>Invitation</h1>
    <p>
        You are corially invited to attend the celebration of the
        Anderson's 50th wedding anniversary on October 15 at 8:00 p.m.
    </p>

    <form action="SendRSVP.php" method="get">
        
    <h2>RSVP</h2>

    <p>
        Name &nbsp;
        <input type="text" name="name" size="50" />
    </p>

    <p>
        <input type="radio" name="attendance" value="yes" />
        I will attend &nbsp;
        <input type="radio" name="attendance" value="no" />
        I will NOT attend &nbsp;
    </p>

    <p>
        Number of guests besides myself &nbsp;
        <input type="text" name="guests" />
    </p>

    <p>
        <input type="submit" value=" Send RSVP" />
        <input type="reset" />
    </p>

    </form>

    <p>
        <a href="attending.php">See Who's Attending</a><br />
        <a href="notattending.php">See Who's Not Attending</a>
    </p>
  </body>
</html>
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein
NewBreed is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-11-2009, 09:18 PM Re: PHP text write
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
At first glance I don't see any errors, are you getting an error message or warning (make sure error reporting is on)? Can you be more descriptive about your problems... Is the file not being written, not being written correctly?
__________________

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
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-11-2009, 09:28 PM Re: PHP text write
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
No errors... See for yourself:
http://codingasylum.freehostia.com/practice/RSVP.html
I tried the function exit(); throughout my code and it wouldn't work where you see

Code:
            if(file_put_contents($YesFile, addslashes($_GET['name']) . ", " . $_GET['guests'] . "\n", FILE_APPEND))
                echo "<p>Thanks for RSVP'ing! We're looking forward to seeing you!</p>";
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein

Last edited by NewBreed; 05-11-2009 at 10:01 PM..
NewBreed is offline
Reply With Quote
View Public Profile
 
Old 05-11-2009, 10:04 PM Re: PHP text write
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
It seems like that call to file_put_contents if failing. Is error reporting on on your server? Try chmod'ing noattending.txt 755.

Also, your code was a bit difficult to read so I reorganized it:
PHP Code:
<html>
  <head>
    <title>RSVP</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>

<?php

if (empty($_GET['name']) || !isset($_GET['attendance']))
    echo 
"<p>You must enter your name and specify whether you will attend! Click your browser's Back button to return to the RSVP form.</p>";

else if(
$_GET['attendance'] == "yes" && !is_numeric($_GET['guests']))
        echo 
"<p>Please specify the number of guests who will accompany to the RSVP form.</p>";
    

else 
{
    if(
$_GET['attendance'] == "yes")
    {
        
$YesFile "attending.txt";
        if(
file_put_contents($YesFileaddslashes($_GET['name']) . ", " $_GET['guests'] . "\n"FILE_APPEND))
            echo 
"<p>Thanks for RSVP'ing! We're looking forward to seeing you!</p>";
        else
            echo 
"<p>Cannot save to the $YesFile file.</p>";
    }

    if(
$_GET['attendance'] == "no")
    {
        
$NoFile "notattending.txt";
        
        if(
file_put_contents($NoFileaddslashes($_GET['name']) . "\n"FILE_APPEND))
            echo 
"<p>Thanks for RSVP'ing! Sorry you can't make it!</p>";
        else
            echo 
"<p>Cannot save to the $NoFile file.</p>";
    }
}
?>
</body>
</html>
by the way, for future reference...

Using double quotes (" ") causes PHP to attempted to parse that string, which isn't necessary if it does not contain a variable (ie "my var = $myVar"). Use single quotes (' ') for strings that don't need to be parsed.
__________________

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; 05-11-2009 at 10:07 PM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-11-2009, 10:22 PM Re: PHP text write
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
This is the books code... not my code. Not that I'm a great programmer, but all that you see has not been edited by me. It's straight from the book onto my server and this forum. I changed the files permissions to 777... still wasn't working. I don't know if it's my server not supporting something or wtf is going on.... Maybe I'll just write all the code out and hope he doesn't upload it on his server to see if it works. lol.
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein
NewBreed is offline
Reply With Quote
View Public Profile
 
Old 05-12-2009, 01:28 AM Re: PHP text write
markAtRitetek's Avatar
Experienced Talker

Posts: 32
Name: Mark Hudson
Location: Atlanta, GA
Trades: 0
With all due respect for your scholastic aspirations, while I'm sure plenty of people love to look at homework assignments, I personally come here to learn more about the leading edge of both web technologies, standards, and business practices. There are plenty of forums where you can get help with your homework, but "webmaster talk" does not seem to be the proper venue for study time.
__________________
Mark Hudson
Ritetek Design

Please login or register to view this content. Registration is FREE
markAtRitetek is offline
Reply With Quote
View Public Profile Visit markAtRitetek's homepage!
 
Old 05-12-2009, 01:47 AM Re: PHP text write
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by markAtRitetek View Post
With all due respect for your scholastic aspirations, while I'm sure plenty of people love to look at homework assignments, I personally come here to learn more about the leading edge of both web technologies, standards, and business practices. There are plenty of forums where you can get help with your homework, but "webmaster talk" does not seem to be the proper venue for study time.
I didn't notice any rule about only questions regarding "leading edge web technologies, standards and practices" being acceptable.

I think its a perfectly legitimate question, and there are plenty of people who arn't on the "leading edge" here (myself included).

Note that had he asked for someone to do his homework for him I wouldn't find his question acceptable. There's nothing wrong with asking for help picking out a bug, especially when you are new to something.
__________________

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; 05-12-2009 at 01:55 AM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-12-2009, 04:50 PM Re: PHP text write
NewBreed's Avatar
Extreme Talker

Posts: 223
Name: Johnny
Location: Washington
Trades: 0
Quote:
Originally Posted by markAtRitetek View Post
With all due respect for your scholastic aspirations, while I'm sure plenty of people love to look at homework assignments, I personally come here to learn more about the leading edge of both web technologies, standards, and business practices. There are plenty of forums where you can get help with your homework, but "webmaster talk" does not seem to be the proper venue for study time.
PHP is a leading edge web technology. Why does it matter if I'm writing php inside of class or outside of class? I do both, it just so happens I wanted some help with my assignment. My goal is to learn php and become good at it, which is why I attend class. This "webmaster talk" you speak of may include writing code in php. By the way web masters ALWAYS study, if you aren't, you become irrelevant. This forum is my second school... You just said yourself you were here to learn, I am as well... along with many, many other people...
<sarcasm>
Did you login to the wrong forum?
</sarcasm>
__________________
"The only thing that interferes with my learning is my education." -Albert Einstein

Last edited by NewBreed; 05-12-2009 at 04:53 PM..
NewBreed is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP text write
 

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