SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    cheshire
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    middle 2 columns of table remain blank!

    I am getting tired now - can you spot why the middle two columns of my table do not update?
    Sorry about the lack of formatting with my scripts etc the always end up a mess!

    I have a script which pops up a form for a student to enter their test marks if they wish to do so, otherwise the form to enter their test name and test mark does not appear. The script shows the test names and test marks for id = 1.
    When I click on the link the form pops up for me to select a test name and a test mark but only the id column and the other id column which is autoincrement get any data. The middle two colums called 'testname' and 'testscore' are blank, yet my script returns a message to say that the scores have been added to the testscores table.
    I don't know why this happens?
    I also get a '0' under the list of test names and test marks that are in the table for student id=1.
    Appreciate some help here please.
    Below is the script

    PHP Code:
    <html>
    <head>
    <title> Connecting to Mysql server at ISP host</title>
    </head>
    <body>
    <?php
    $Host 
    "***********";// Set the variables for the database access:
    $User "****";
    $Password "******";       
    $DBName "*******";     
    $TableName "testscores";

    $link = @mysql_connect("$Host""$User""$Password");
    if (!
    $link)
     {
     print(
    "<P>Unable to connect to the " .       
     
    "database server at this time.</P>\n");      //note how 2 strings have been concatonated
     
    exit();
    }
    else
    {
    print(
    "Your now connected to the Mysql server at the host ISP.<P>\n");
    }

    if (! @
    mysql_select_db("$DBName") )
     {
     print(
    "<P>Unable to locate the $DBName database at this time.</P>\n");
     exit();
     }
     else
    {
    print(
    "The database $DBName has been located.</P>\n");
    }


    // If the user wants to add a score
     
    if (isset($addscore)){

    print (
    "<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n");
    print (
    "<P>Select the name of the test you have just taken :<br>\n"); 

    // Create the test pull-down menu.
    print ("Select a test:<BR>\n");
    print (
    "<SELECT NAME=testname><OPTION>Choose One</OPTION>\n");
    print (
    "<OPTION VALUE=Life Test>Life Test</OPTION>\n");
    print (
    "<OPTION VALUE=Cells Test>Cells Test</OPTION>\n");
    print (
    "<OPTION VALUE=Digestion Test>Digestion Test</OPTION>\n");
    print (
    "<OPTION VALUE=Circulation Test>Circulation Test</OPTION>\n");
    print (
    "<OPTION VALUE=Respiration Test>Respiration Test</OPTION>\n");
    print (
    "<OPTION VALUE=Microbe Test>Microbe Test</OPTION>\n");
    print (
    "</SELECT>\n");

    // Create the score pull-down menu.
    print ("<P>Select your score:<BR>\n");
    print (
    "<SELECT NAME=testscore><OPTION>Choose One</OPTION>\n");
    $score 1;
    while (
    $score <= 25) {
      print (
    "<OPTION VALUE=$score>$score</OPTION>\n");
      
    $score++;
    }
    print (
    "</SELECT>\n");
    print (
    "<p><INPUT TYPE=SUBMIT NAME=addscore VALUE=\"SUBMIT\">");
    print (
    "</FORM>\n");

    }
    //close the if isset



    ?>


    <P> Here are all the scores in our database: </P>
    <BLOCKQUOTE>


    <?php

    // If a score has been submitted,
     // add it to the database.
     
    if ("SUBMIT" == $addscore) {
     
    $sql "INSERT INTO $TableName SET " .
     
    "testname=$testname, " .
     
    "testscore=$testscore," .
     
    "id='1'";
     if (
    mysql_query($sql)) {
     echo(
    "<P>Your score has been added.</P>");
     } else {
     echo(
    "<P>Error adding submitted score: " .
     
    mysql_error() . "</P>");
     }
     }

     
     
    // Request the scores for id=1 from the testscores table
     
    $Query "SELECT testname, testscore FROM $TableName WHERE id=1";
     
    $result mysql_query($Query); 
     if (!
    $result) {
     echo(
    "<P>Error performing query: " .
     
    mysql_error() . "</P>");
     exit();
     }


     
    // Display the test name and test score
     
    while ( $row mysql_fetch_array($result) ) {
     echo(
    $row["testname"] . " " $row["testscore"] . "</br>");
     }


    ?>


    </BLOCKQUOTE>

    <?php
    // When clicked, this link will load this page
     // with the joke submission form displayed.
     
    echo("<P><A HREF='$PHP_SELF?addscore=1'>" .
     
    "Add a Test Score!</A></P>");
     

    mysql_close($link);
    ?>
    </body>
    </html>

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    cheshire
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    partly solved

    I have made some progress. By adding single qoutes as below:

    "testname='$testname', " .
    "testscore='$testscore'," .
    "id='1'";

    But I get back:

    Life 4

    Instead of:

    Life Test 4

    The second word of the test name gets lost - do I need to use urlencode - if so how please?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    cheshire
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    solved

    Problem solved by the following:

    value=\"Life Test\"

  4. #4
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, glad i could help !
    . . . chris


Bookmarks

Posting Permissions

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