Results 1 to 8 of 8

Thread: [RESOLVED] Help again sorry

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] Help again sorry

    Can anyone tell me why this code isnt showing me the form on my website click the link and youll see what i mean.?

    http://www.webspace4rent.biz/guestbook/sign.php

    below is the code.

    PHP Code:
    <html><head><title>Sign the guestbook</title></head>
    <body>
    <?php        $self $_SERVER['PHP_SELF'];
                 
    $name $_POST['name'];
                 
    $email $_POST['email'];
                 
    $comments $_POST['comments'];
                 
    $submit $_POST['submit'];

    #the html form

    $form "<form action=\"$self\" method=\"post\">";
    $form.= "Name: <input type=\"text\" name=\"name\" ";
    $form.= "size=\"50\" value=\"$name\"> <br>";
    $form.= "Email: <input type=\"text\" name=\"email\" ";
    $form.= "size=\"50\" value=\"$email\"> <br>";
    $form.= "Comments:<br>";
    $form.= "<textarea name=\"comments\" cols=\"45\" ";
    $form.= "rows=\"4\">$comments</textarea> <br>";
    $form.= "<input type=\"submit\" name=\"submit\" ";
    $form.= "value=\"sign\"> </form>";

    #on first opening display the form

    if( !$submit) { $msg $form; }

    #or redisplay a message and the form if incomplete

    else if( !$name or !$email or !$comments; }

    $msg "<b>PLease complete all the fields</b><br><br>";
      
    $msg.= $form; }

    #or add the form data to the guestbook database table
    else #otherwise connect to MySQL

    $conn = @mysql_connect"localhost""webspace_guest""brodie" )
      or die( 
    "Could not connect to database" );

    #select the database

    $rs = @mysql_select_db"webspace_guest"$conn )
        or die ( 
    " Could not select database" );

    #create the SQL query

    if( $name and $comments )
    {
      
    $sql ="insert into guestbook (name email, comments)
               value(\$name\",\"
    $email\",\"$comments\")";
      
    $rs = @mysql_query$sql $conn )
              or die (
    "Could not execute SQL query");}

    #confirm entry and display a link to view guestbook

    if($rs)
    $msg "<h3>Thank you  - your entry has been saved.";
      
    $msg "<br><a href = \"view.php\">";
      
    $msg "View My Guestbook</a></h3>"; }
    }

    #write the page

    echo( $msg );
    ?>
    </body></html>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Help again sorry

    Double check your braces.

    Just with a quick look I noticed that

    PHP Code:
    else if( !$name or !$email or !$comments; } 
    should be

    PHP Code:
    else if( !$name or !$email or !$comments 

    You also missed a comma on
    PHP Code:
    $rs = @mysql_query$sql $conn 
    it should be
    PHP Code:
    $rs = @mysql_query$sql$conn 
    After that, it should load.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help again sorry

    I have got it to show now when i fill out the form and click submit it says PLease complete all the fields but all fields have been typed in?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Help again sorry

    Can you post your updated code, please?

    Just the basics of


    PHP Code:
    <html><head><title>Sign the guestbook</title></head>
    <body>
    <?php        $self $_SERVER['PHP_SELF'];
                 
    $name $_POST['name'];
                 
    $email $_POST['email'];
                 
    $comments $_POST['comments'];
                 
    $submit $_POST['submit'];

    #the html form

    $form "<form action=\"$self\" method=\"post\">";
    $form.= "Name: <input type=\"text\" name=\"name\" ";
    $form.= "size=\"50\" value=\"$name\"> <br>";
    $form.= "Email: <input type=\"text\" name=\"email\" ";
    $form.= "size=\"50\" value=\"$email\"> <br>";
    $form.= "Comments:<br>";
    $form.= "<textarea name=\"comments\" cols=\"45\" ";
    $form.= "rows=\"4\">$comments</textarea> <br>";
    $form.= "<input type=\"submit\" name=\"submit\" ";
    $form.= "value=\"sign\"> </form>";

    #on first opening display the form

     
    if( !$name or !$email or !$comments )

    $msg "<b>PLease complete all the fields</b><br><br>";
      
    $msg.= $form; } else { $msg $form ;}


    echo( 
    $msg );
    echo (
    "Name: " $name "<br />");
    echo (
    "Email: " $email "<br />");
    echo (
    "Comments: " $comments "<br />");
    ?>
    </body></html>
    Seems to work fine.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Help again sorry

    This is the code but it says when i try to submit the fields it says could not execute the query.

    Code:
    <html><head><title>Sign the guestbook</title></head> 
    <body> 
    <?php        $self = $_SERVER['PHP_SELF']; 
                 $name = $_POST['name']; 
                 $email = $_POST['email']; 
                 $comments = $_POST['comments']; 
                 $submit = $_POST['submit']; 
    
    #the html form 
    
    $form = "<form action=\"$self\" method=\"post\">"; 
    $form.= "Name: <input type=\"text\" name=\"name\" "; 
    $form.= "size=\"50\" value=\"$name\"> <br>"; 
    $form.= "Email: <input type=\"text\" name=\"email\" "; 
    $form.= "size=\"50\" value=\"$email\"> <br>"; 
    $form.= "Comments:<br>"; 
    $form.= "<textarea name=\"comments\" cols=\"45\" "; 
    $form.= "rows=\"4\">$comments</textarea> <br>"; 
    $form.= "<input type=\"submit\" name=\"submit\" "; 
    $form.= "value=\"sign\"> </form>"; 
    
    #on first opening display the form 
    
    if( !$submit) { $msg = $form; } 
    
    #or redisplay a message and the form if incomplete 
    
    else if( !$name or !$email or !$comments )
    
    { $msg = "<b>PLease complete all the fields</b><br><br>"; 
      $msg.= $form; } 
    
    #or add the form data to the guestbook database table 
    else #otherwise connect to MySQL 
    
    { $conn = @mysql_connect( "localhost", "webspace_guest", "brodie" ) 
      or die( "Could not connect to database" ); 
    
    #select the database 
    
    $rs = @mysql_select_db( "webspace_guest", $conn ) 
        or die ( " Could not select database" ); 
    
    #create the SQL query 
    
    if( $name and $comments ) 
    { 
      $sql ="insert into guestbook (name, email, comments) 
               values(\$name\",\"$email\",\"$comments\")"; 
      $rs = @mysql_query( $sql, $conn ) 
              or die ("Could not execute SQL query");} 
    
    #confirm entry and display a link to view guestbook 
    
    if($rs) 
    { $msg = "<h3>Thank you  - your entry has been saved."; 
      $msg = "<br><a href = \"view.php\">"; 
      $msg = "View My Guestbook</a></h3>"; } 
    } 
    
    #write the page 
    
    echo( $msg ); 
    ?> 
    </body></html>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Help again sorry

    If that is the only problem, you're missing a quote here:

    PHP Code:
    $sql ="insert into guestbook (name, email, comments) 
               values(\$name\",\"
    $email\",\"$comments\")"
    should be

    PHP Code:
    $sql ="insert into guestbook (name, email, comments) 
               values(\"
    $name\",\"$email\",\"$comments\")"

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Help again sorry

    Jamie, I suggest you buy yourself a book and learn how to code using PHP; instead of asking us to solve your problems for you.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Help again sorry

    Quote Originally Posted by visualAd
    Jamie, I suggest you buy yourself a book and learn how to code using PHP; instead of asking us to solve your problems for you.
    Not necessarily a coding book, but reading up on popular debugging practices would definitely help.

Posting Permissions

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



Click Here to Expand Forum to Full Width