What stupid mistake have I done now?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    What stupid mistake have I done now?

    Hi,

    When I press sign(submit) - It looks like something is wrong and the code does not want to insert the info into my SQL...I get the error message "could not query.." that I type in under "#create the sql query" I went trough the book I got the script from and check to see that all of the spaces and letter is exactly as it should be..I am still learning php and figure I made a stupid mistake that problem someone that is fluent in PHP will pick up directly.

    [PHP]
    <?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\">$co mments</textarea> <br>";
    $form.= "<input type=\"submit\" name=\"submit\" ";
    $form.= "value=\"Sign\" > </from>";

    #on first opening display the from
    if ( !$submit) { $msg = $form; }

    #or redsiplay a message and the from if incomplete
    else if( !$name or !$email or !$comments)
    { $msg = "<b>Please complete all fields</b><br><br>";
    $msg.= $form; }

    #or add the from data to the guestbook database table
    else #otherwise connect to mysql
    { $conn = @mysql_connect( "localhost" , "webandwe_weban dwe", "mysql" )
    or die ( "could not connect to database" );

    #select the database
    $rs = @mysql_select_d b( "webandwe_conta ct", $conn)
    or die ("could not select database");

    #create the sql query
    if( $name and $comments )
    {
    $sql ="insert into guestbook (name, e-mail, comments)
    values(\"$name\ ",\"$email\",\" $comments\")";
    $rs = @mysql_query( $sql, $conn )
    or die ( "could not execute SQL query" ); }

    #confirm entery and display
    if ($rs)
    { $msg = "<h3>thank you - your entry has been saved.";
    $msg.= "<br><a href = \"guestbook-view.php\">";
    $msg.= "View my guestbook</a></h3>"; }
    }
    #write the page
    echo ( $msg );
    ?>
    [/PHP]
Working...