PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 14th, 2002, 01:10 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
beginner seeks help

okay, so i had ago at matts news program, I thought it was great, so I thought it would be cool to customise it into a guestbook, anyways, as I am a pure beginner at this it didn't go to plan i guess, here is my code at the moment I'm getting an error on the line where the form starts. Its probably just complete crap what i've got there, but i guess its a start

Code:
<?php

if ( $action == "sign" ) {

echo( "Leave your mark!" );

echo( "<br><br>" );

echo( "<FORM ACTION="<?=$PHP_SELF?action=sign>" METHOD="POST" NAME="gbook">
Name:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name" class="textbox"><BR>
Email:<BR>
<INPUT TYPE="text" SIZE="30" NAME="email" class="textbox"><BR>
The News:<BR>
<TEXTAREA NAME="message" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!" class=button> 
<input type="reset" class="button"><BR>
</FORM>" );

$line = date("l, F dS Y - H:m:s",1000000000) . "|" . $HTTP_POST_VARS['name'];
        $line .= "|" . $HTTP_POST_VARS['email'];
        $line .= "|" . $HTTP_POST_VARS['message'];
        $line = str_replace("rn","<BR>",$line);
        $line .= "rn";
        fwrite($fp, $line);
        if(!fclose($fp)) {
            echo "Error closing file!";
            exit;
        }
        echo ( "<b>Message Added added!</b> 
        <a href="gbook.php">View Your Message</a>" );    
    }

exit;
}


echo ("&nbsp;<a href="$PHP_SELF?action=sign" class=link>Sign The Guest Book</a>");

echo ("<BR><BR>" );

$data = file('./yepyep/gbook.txt');
$data = array_reverse($data);
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
    echo . "<b>Posted by <a href="mailto:$pieces[2]">" . $pieces[1] . 
    "</a> on" . $pieces[0] . "</b><br>" . $pieces[3] . "<br><br>";
}

?>

Reply With Quote
  #2  
Old May 14th, 2002, 01:34 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: beginner seeks help

Whenever you use a quote (") inside of a quote ("), you need to escape the inside quote:

echo " I said,"hello" to him.";

is wrong, it should be:

echo " I said,"hello" to him.";

also, on the portion that reads:

<?=$PHP_SELF

you don't need to do the <?= and the



Reply With Quote
  #3  
Old May 14th, 2002, 07:55 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: beginner seeks help

thank you for your help, that has got me down abit further, now im on this line where the exit is

php Code:
Original - php Code
  1.  
  2.  if(!fclose($fp)) {
  3.             echo "Error closing file!";
  4.             exit;
  5.  

Reply With Quote
  #4  
Old May 14th, 2002, 08:15 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: beginner seeks help

Hmm..I don't see a fopen call any where above that. You can't fclose a file that you haven't opened.

Please post the error message you get in the future and it may help to figure out exactly what is happening...


Reply With Quote
  #5  
Old May 14th, 2002, 08:23 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: beginner seeks help

okay, the error I get is
Parse error: parse error in /home/gmflp/public_html/test.php on line 45

here is my full code of what I have so far

php Code:
Original - php Code
  1.  
  2. <html>
  3.  
  4. <head>
  5.     <title>[...Good.Music.For.Lame.People...]</title>
  6.  
  7. <link type="text/css" href="scripts/gmflp.css" rel="stylesheet">
  8.  
  9.  
  10.  
  11.  
  12. </head>
  13.  
  14. <body bgcolor="#ffffff">
  15. <font class=gmflp>
  16.  
  17. <?php
  18.  
  19. if ( $action == "sign" ) {
  20.  
  21. echo( "Leave your mark!" );
  22.  
  23. echo( "<br><br>" );
  24.  
  25. echo( "<FORM ACTION=<=$PHP_SELF?action=sign> METHOD=POST NAME=gbook>
  26. Name:<BR>
  27. <INPUT TYPE=text SIZE=30 NAME=name class=textbox><BR>
  28. Email:<BR>
  29. <INPUT TYPE=text SIZE=30 NAME=email class=textbox><BR>
  30. Message:<BR>
  31. <TEXTAREA NAME=message COLS=40 ROWS=5></TEXTAREA>
  32. <BR><BR>
  33. <INPUT TYPE=submit NAME=submit VALUE=Post it! class=button> <input type=reset class=button><BR>
  34. </FORM>" );
  35.  
  36. $line = date("l, F dS Y - H:m:s",1000000000) . "|" . $HTTP_POST_VARS['name'];
  37.         $line .= "|" . $HTTP_POST_VARS['email'];
  38.         $line .= "|" . $HTTP_POST_VARS['message'];
  39.         $line = str_replace("rn","<BR>",$line);
  40.         $line .= "rn";
  41.         fwrite($fp, $line);
  42.         if(!fclose($fp)) {
  43.             echo "Error closing file!";
  44.  
  45. echo( "<b>Message Added added!</b> <a href="gbook.php">View Your Message</a>" );   
  46.     }
  47.  
  48.  
  49.  
  50. echo ( "&nbsp;<a href="$PHP_SELF?action=sign" class=link>Sign The Guest Book</a>" );
  51.  
  52. echo ("<BR><BR>" );
  53.  
  54. $data = file('./yepyep/gbook.txt');
  55. $data = array_reverse($data);
  56. foreach($data as $element) {
  57.     $element = trim($element);
  58.     $pieces = explode("|", $element);
  59.     echo( "<b>Posted by <a href="mailto:$pieces[2]>$pieces[1]</a> on $pieces[0] </b><br>$pieces[3]<br><br>;
  60. }
  61.  
  62.  
  63. ?>
  64.  
  65.  
  66.  
  67.  
  68. </body>
  69.  
  70. </html>

Reply With Quote
  #6  
Old May 14th, 2002, 08:30 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: beginner seeks help

You missed the closing ") on that last echo...


and check the syntax at the beginning of that same echo..looks like you forgot to escape the first quote of the <a> tag and forgot to use a quote to finish off the mailto:



Reply With Quote
  #7  
Old May 14th, 2002, 08:45 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: beginner seeks help

okay man, Ive made the changes
now I get the same error, just a different line
Parse error: parse error in /home/gmflp/public_html/test.php on line 62

which is basicly the same place

php Code:
Original - php Code
  1.  
  2. <html>
  3. <body bgcolor="#ffffff">
  4. <font class=gmflp>
  5.  
  6. <?php
  7.  
  8. if ( $action == "sign" ) {
  9.  
  10. echo( "Leave your mark!" );
  11.  
  12. echo( "<br><br>" );
  13.  
  14. echo( "<FORM ACTION=<=$PHP_SELF?action=sign> METHOD=POST NAME=gbook>
  15. Name:<BR>
  16. <INPUT TYPE=text SIZE=30 NAME=name class=textbox><BR>
  17. Email:<BR>
  18. <INPUT TYPE=text SIZE=30 NAME=email class=textbox><BR>
  19. Message:<BR>
  20. <TEXTAREA NAME=message COLS=40 ROWS=5></TEXTAREA>
  21. <BR><BR>
  22. <INPUT TYPE=submit NAME=submit VALUE=Post it! class=button> <input type=reset class=button><BR>
  23. </FORM>" );
  24.  
  25. if($HTTP_POST_VARS['submit']) {
  26.         if(!$HTTP_POST_VARS['name']) {
  27.             echo "You must enter a name";
  28.             exit;
  29.         }
  30.         if(!$HTTP_POST_VARS['email']) {
  31.             echo "You must enter an email address";
  32.             exit;
  33.         }
  34.         if(!$HTTP_POST_VARS['message']) {
  35.             echo "You must enter your message";
  36.             exit;
  37.         }
  38.         if(strstr($HTTP_POST_VARS['name'],"|")) {
  39.             echo "Name cannot contain the pipe symbol - |";
  40.             exit;
  41.         }
  42.         if(strstr($HTTP_POST_VARS['news'],"|")) {
  43.             echo "News cannot contain the pipe symbol - |";
  44.             exit;
  45.         }
  46.         $fp = fopen('./yepyep/gbook.txt','a');
  47.         if(!$fp) {
  48.             echo "Error opening file!";
  49.             exit;
  50.         }
  51.  
  52. $line = date("l, F dS Y - H:m:s",1000000000) . "|" . $HTTP_POST_VARS['name'];
  53.         $line .= "|" . $HTTP_POST_VARS['email'];
  54.         $line .= "|" . $HTTP_POST_VARS['message'];
  55.         $line = str_replace("rn","<BR>",$line);
  56.         $line .= "rn";
  57.         fwrite($fp, $line);
  58.         if(!fclose($fp)) {
  59.             echo "Error closing file!";
  60.             exit;
  61.        }
  62.  
  63. echo( "<b>Message Added added!</b> <a href="gbook.php">View Your Message</a>" );   
  64.     }