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 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cant get this simple class assignment working :-(

    Hello everyone, for this class assignment I have to just copy and paste out of the book but its not working!!! How is that even possible. I sharing the simple code here but Ill also share what Im getting from it:
    You must enter your first and last name! Click your browser's Back button to return to the Guest Book form."; else { $DBConnect = @mysql_connect("localhost", "mgs314", "password"); if ($DBconnect === FALSE) echo "

    Ubable to connect to the database server.
    " . "

    Error Code " . mysql_errno() . ": " . mysql_error() . "
    "; else { $DBName = "guestbook"; if (!@mysql_select_db($DBName, $DBConnect)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult ===FALSE) echo "

    Unable to execute the query.
    " . "

    Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
    "; else echo "

    You are the first visitor!

    "; } mysql_select_db($DBName, $DBConnect); $TableName = "visitors"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) { $SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"; $QueryResult = @myswl_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "

    Unable to create the table.
    " . "

    Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
    "; $LastName = stripslashes($_POST['last_name']); $FirstName = stripslashes($_POST['first_name']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "

    Unable to execute the query.
    " . "

    Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
    "; else echo "
    Thank you for signing our guest book!
    "; } mysql_close($DBConnect); } } ?>
    And here are the two pages code:
    Code:
    <form method="POST" action="signguestbook.php">
    <p>First Name <input type="text" name="first_name" /></p>
    <p>Last Name <input type="text" name="last_name" /></p>
    <p><input type="submit" value="Submit"></p>
    </form>
    and the php page that it sends to:

    PHP Code:
    <?php

    if (empty($_POST['first_name']) OR empty($_POST['last_name']))
        echo 
    "<p>You must enter your first and last name! Click your browser's Back button to return to the Guest Book form.</p>";

    else {
        
    $DBConnect = @mysql_connect("localhost""mgs314""password");
        if (
    $DBconnect === FALSE)
            echo 
    "<p>Ubable to connect to the database server.</p>" "<p>Error Code " mysql_errno() . ": " mysql_error() . "</p>";
        else {
            
    $DBName "guestbook";
            if (!@
    mysql_select_db($DBName$DBConnect)) {
                
    $SQLstring "CREATE DATABASE $DBName";
                
    $QueryResult = @mysql_query($SQLstring$DBConnect);
                if (
    $QueryResult ===FALSE)
                    echo 
    "<p>Unable to execute the query.</p>" "<p>Error code " mysql_errno($DBConnect) . ": " mysql_error($DBConnect) . "</p>";
                        else
                            echo 
    "<p> You are the first visitor!<p>";
            }
            
    mysql_select_db($DBName$DBConnect);
            
            
    $TableName "visitors";
            
    $SQLstring "SHOW TABLES LIKE '$TableName'";
            
    $QueryResult = @mysql_query($SQLstring$DBConnect);
            if (
    mysql_num_rows($QueryResult) == 0) {
                
    $SQLstring "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))";
                
    $QueryResult = @myswl_query($SQLstring$DBConnect);
                if (
    $QueryResult === FALSE)
                    echo 
    "<p> Unable to create the table.</p>" "<p>Error code " mysql_errno($DBConnect) . ": " mysql_error($DBConnect) . "</p>";
                    
            
    $LastName stripslashes($_POST['last_name']);
            
    $FirstName stripslashes($_POST['first_name']);
            
    $SQLstring "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')";
            
    $QueryResult = @mysql_query($SQLstring$DBConnect);
            if (
    $QueryResult === FALSE)
                echo 
    "<p>Unable to execute the query.</p>" "<p>Error  code " mysql_errno($DBConnect) . ": " mysql_error($DBConnect) . "</p>";
            
            else
                echo 
    "<h1>Thank you for signing our guest book!</h1>";
            }
            
    mysql_close($DBConnect);
        }
    }
        
        
    ?>
    Both are using Strict DTD.

    Thanks in Advance for the help!

  • #2
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Perhaps you can help us out by explaining what isn't working and what errors you're getting?
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If that first block is your actual output you will need to use a machine that has PHP installed.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    New Coder
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Lamped View Post
    Perhaps you can help us out by explaining what isn't working and what errors you're getting?
    Its simply not working, as in, not outputting anything I need. It outputs the first sentence correctly but then just outputs all the php code afterwords.

    You must enter your first and last name! Click your browser's Back button to return to the Guest Book form."; else { $DBConnect = @mysql_connect("localhost", "mgs314", "password"); if ($DBconnect === FALSE) echo "

    Ubable to connect to the database server.
    " . "

    Error Code " . mysql_errno() . ": " . mysql_error() . "
    "; else { $DBName = "guestbook"; if (!@mysql_select_db($DBName, $DBConnect)) { $SQLstring = "CREATE DATABASE $DBName"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult ===FALSE) echo "

    Unable to execute the query.
    " . "

    Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
    "; else echo "

    You are the first visitor!

    "; } mysql_select_db($DBName, $DBConnect); $TableName = "visitors"; $SQLstring = "SHOW TABLES LIKE '$TableName'"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if (mysql_num_rows($QueryResult) == 0) { $SQLstring = "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"; $QueryResult = @myswl_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "

    Unable to create the table.
    " . "

    Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
    "; $LastName = stripslashes($_POST['last_name']); $FirstName = stripslashes($_POST['first_name']); $SQLstring = "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')"; $QueryResult = @mysql_query($SQLstring, $DBConnect); if ($QueryResult === FALSE) echo "

    Unable to execute the query.
    " . "

    Error code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "
    "; else echo "
    Thank you for signing our guest book!
    "; } mysql_close($DBConnect); } } ?>
    See it says nothing is getting inserted when in fact I do have both fields with data and then it outputs that there is nothing in those fields, afterwards it just outputs all my php code and doesnt even translate it into html....

  • #5
    New Coder
    Join Date
    Oct 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im trying to run this all local using the Unifrom Server and its suppose to just naturally support PHP.

    EDIT: And the first echo works fine.
    Last edited by talimore1; 12-05-2010 at 11:14 PM.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    So it doesn't show the:
    PHP Code:
    <?php

    if (...
    Part? That would indicate something has gone awry with the text file itself. Open it up in notepad and save it in ansi and try again. Something could be wrong with any of those special characters that may cause this.

    If it does show the <?php part (check your source code, since it starts with a < it is considered to be an element) then it is not processing your PHP. If you are accessing from the file:// protocol, then this PHP won't parse. If you are accessing it from http:// then its your webserver that is choking on it (and I have never used Unifrom Server so I can't help you on that).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It was talked about in class today duh!

    PHP Code:
    <?php 

    if (empty($_POST['first_name']) OR empty($_POST['last_name'])) 
        echo 
    "<p>You must enter your first and last name! Click your browser's Back button to return to the Guest Book form.</p>"

    else { 
        
    $DBConnect = @mysql_connect("localhost""mgs314""password"); 
        if (
    $DBconnect === FALSE
            echo 
    "<p>Ubable to connect to the database server.</p>" "<p>Error Code " mysql_errno() . ": " mysql_error() . "</p>"
        else { 
            
    $DBName "guestbook"
            if (!@
    mysql_select_db($DBName$DBConnect)) { 
                
    $SQLstring "CREATE DATABASE $DBName"
                
    $QueryResult = @mysql_query($SQLstring$DBConnect); 
                if (
    $QueryResult ===FALSE
                    echo 
    "<p>Unable to execute the query.</p>" "<p>Error code " mysql_errno($DBConnect) . ": " mysql_error($DBConnect) . "</p>"
                        else 
                            echo 
    "<p> You are the first visitor!<p>"
            } 
            
    mysql_select_db($DBName$DBConnect); 
        } <- 
    add me here maybe ***********************************************
            
    $TableName "visitors"
            
    $SQLstring "SHOW TABLES LIKE '$TableName'"
            
    $QueryResult = @mysql_query($SQLstring$DBConnect); 
            if (
    mysql_num_rows($QueryResult) == 0) { 
                
    $SQLstring "CREATE TABLE $TableName (countID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, last_name VARCHAR(40), first_name VARCHAR(40))"
                
    $QueryResult = @myswl_query($SQLstring$DBConnect); 
                if (
    $QueryResult === FALSE
                    echo 
    "<p> Unable to create the table.</p>" "<p>Error code " mysql_errno($DBConnect) . ": " mysql_error($DBConnect) . "</p>"
                     
            
    $LastName stripslashes($_POST['last_name']); 
            
    $FirstName stripslashes($_POST['first_name']); 
            
    $SQLstring "INSERT INTO $TableName VALUES(NULL, '$LastName', '$FirstName')"
            
    $QueryResult = @mysql_query($SQLstring$DBConnect); 
            if (
    $QueryResult === FALSE
                echo 
    "<p>Unable to execute the query.</p>" "<p>Error  code " mysql_errno($DBConnect) . ": " mysql_error($DBConnect) . "</p>"
             
            else 
                echo 
    "<h1>Thank you for signing our guest book!</h1>"
            } 
            
    mysql_close($DBConnect); 
        } 
    } <- 
    delete me here maybe******************************************
         
        
    ?>
    Last edited by ProfessorMurray; 12-08-2010 at 04:25 AM.


  •  

    Posting Permissions

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