Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New to php - need some help

    Hi, I just started learning php and I need some help, I am trying to make a guestbook, I thought this code would work but it doesn't:
    PHP Code:
    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor=gold>
    <font size=7><center><b><u>Guest Book</u></b></font><br><br>
    <?php
        
    include("guestbook.php");
        
        if(
    $submitted);
        {
        if((
    Name=="")&&(comments=="")){
        echo (
    "You forgot to sign your name and comments!");
        }
        
    $file fopen("guestbook.php""a");
        
    fputs($file'<hr>');
        
    fputs($file$Name);
        
    fputs($file'<HR>');
        
    fputs($file'<center>');
        
    fputs($file$comments);
        
    fputs($file'<hr><hr>');
        
    fclose($file);

        }
        echo (
    '<form action="veiw_bg.php" method="post">Sign The Guestbook<Br><hr>Your Name: <input type=text MAXLENGTH=10 Name="Name"><br>Comments: <textarea rows=10 cols=100 Name="comments"></textarea><br><input name="submitted" type="hidden" value="true"><input type="submit" Value="Leave your comments"></form>')
    ?>
    </body>
    </html>

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I think your syntax for the include statement is wrong try

    PHP Code:
    include "guestbook.php"
    Also this project isn't a good one to learn php on you should try simple php projects. I also noticed at least one odd spelling mistake "veiw_bg.php" shouldn't that be view?


    Leonard Whistler
    www.stubby.ca
    Leonard Whistler

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Include is right

    Ok, here's what it should be
    PHP Code:
     <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor=gold>
    <font size=7><center><b><u>Guest Book</u></b></font><br><br>
    <?php
        
    include("guestbook.php");
        
        if(isset(
    $_POST['submitted']));
        {
        if((
    $_POST['Name']=="")&&($_POST['comments']=="")){
        echo (
    "You forgot to sign your name and comments!");
        }
        
    $file fopen("guestbook.php""a");
        
    fputs($file'<hr>');
        
    fputs($file$_POST['Name']);
        
    fputs($file'<HR>');
        
    fputs($file'<center>');
        
    fputs($file$_POST['comments']);
        
    fputs($file'<hr><hr>');
        
    fclose($file);

        }else{
        echo (
    '<form action="veiw_bg.php" method="post">Sign The Guestbook<Br><hr>Your Name: <input type=text MAXLENGTH=10 Name="Name"><br>Comments: <textarea rows=10 cols=100 Name="comments"></textarea><br><input type="submit" Value="Leave your comments" name="submitted"></form>')
        }
    ?>
    </body>
    </html>

  • #4
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    You can use
    PHP Code:
    include ('guestbook.php'); 
    , everthough Nightfire has already answered your question.

  • #5
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, actually about 20 minutes after I made that post I relised that all I had to do is put a else in after the if comments and name are there box, This wasn't a hard project to start on. I aready know JavaScript and HTML so this wasn't very hard. But php is really cool. It is a ton better than JavaScript. I am tryin to learn this. I might have some more questions about php. But I really like it. Man I could create a really good forum with this...

  • #6
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ARGH!! more errors:
    PHP Code:
    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor=gold>
    <font size=7><center><b><u>Guest Book</u></b></font><br><br>
    <?php
        
    include("guestbook.php");
        
        if(
    $submitted);
        {
        if((
    $_POST['Name']=="")&&($_POST['comments']=="")){
        echo (
    "You forgot to sign your name and comments!");
        }
        else
            {
        
    $file fopen("guestbook.php""a");
        
    fputs($file'<table bgcolor="grey"><tr><td>');
        
    fputs($file'<hr>');
        
    fputs($file'Name: &nbsp;&nbsp;');
        
    fputs($file$_POST['Name']);
        
    fputs($file'<HR>');
        
    fputs($file'<center>');
        
    fputs($file'Comments:<br>');
        
    fputs($file$_POST['comments']);
        
    fputs($file'<hr><hr>');
        
    fputs($file'</table>');
        
    fclose($file);
            }
        }
        echo (
    '<form action="veiw_bg.php" method="post">Sign The Guestbook<Br><hr>Your Name: <input type=text MAXLENGTH=10 Name="Name"><br>Comments: <textarea rows=10 cols=100 Name="comments"></textarea><br><input name="submitted" type="hidden" value="true"><input type="submit" Value="Leave your comments"></form>')
    ?>
    </body>
    </html>
    it works fine, but you have to hit refresh to see what happened and that causes it to send again and....

  • #7
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Include a "no-cache" meta tag, as well you could put the "Sign Guestbook" part on a different page and after it is posted just redirect back to your guestbook.php. (Not that hard)
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Here you go. Copy all of this
    PHP Code:
    <?php
    if(isset($_POST['submitted']));
        {
        if((
    $_POST['Name']=="")&&($_POST['comments']=="")){
        echo (
    "You forgot to sign your name and comments!");
        }else{
        
    $file fopen("guestbook.php""a");
        
    fputs($file'<hr>');
        
    fputs($file$_POST['Name']);
        
    fputs($file'<HR>');
        
    fputs($file'<center>');
        
    fputs($file$_POST['comments']);
        
    fputs($file'<hr><hr>');
        
    fclose($file);
        
    header("Location:veiw_bg.php");
        }
    }
    ?>
    <html>
    <head>
    <title>Guestbook</title>
    </head>
    <body bgcolor=gold>
    <font size=7><center><b><u>Guest Book</u></b></font><br><br>
    <?php
        
    include("guestbook.php");
        
        echo (
    '<form action="veiw_bg.php" method="post">Sign The Guestbook<Br><hr>Your Name: <input type=text MAXLENGTH=10 Name="Name"><br>Comments: <textarea rows=10 cols=100 Name="comments"></textarea><br><input type="submit" Value="Leave your comments" name="submitted"></form>')
        
    ?>
    </body>
    </html>

  • #9
    Regular Coder
    Join Date
    Mar 2004
    Posts
    232
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Warning: Cannot modify header information - headers already sent by (output started at /home/www/stophon4/guestbook/veiw_bg.php:3) in /home/www/stophon4/guestbook/veiw_bg.php on line 19

    I fot that error...

    EDIT: it works fine, your code worked, I just modified it slightly. Except the only problem is when you load the page there is nothin in the two of them. So it brings up the error.

    EDIT2: That's fixed
    Last edited by stophon4; 04-11-2004 at 11:27 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •