SitePoint Sponsor

User Tag List

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

    Its in the URL but not printed to screen

    Hi
    I have altered a few things in my script that sends info to another page. Basically, I can see the info I have sent in the URL of the target page, it looks like this:

    /~p0c79/teacher.php?UserName=David+Graham&logondetails=1+password

    And now all the page is asked to do is print the UserName like this:

    print("Greetings " . $UserName . "<br>\n");

    However, all I get is 'Greetings' , nothing else. Is it because I have also passed other info called logondetails?

    I have enclosed the scripts, here is the form script:

    <HTML>
    <HEAD>
    <TITLE> Sample Page </TITLE>
    </HEAD>
    <BODY>
    PHP Code:
    <?php
    if ($Message == "Invalid") {
        print (
    "<B><CENTER><FONT COLOR=RED>The id and password you entered do not match what is on file. Please try again!</FONT></CENTER></B>\n");
    }


     if (isset(
    $firstname) AND isset($surname) AND isset($password) AND isset($userid))
    {
    $name=$firstname " " $surname;
    $logondetails=$userid " " $password;
    // Now we will welcome the user to our site.
    print("<P><b><center>Wellcome: $name </center></b><br> This is the feedback part of the \'Humans As Organisms\' module.<P>\n");

    $name=urlencode($name);
    $logondetails=urlencode($logondetails);

    print(
    "<P>Click here <A HREF= \"bestpassword5.php?name=$name&logondetails=$logondetails\">link</A>\n");
    print(
    " to be taken to a page that will display your test results.</P>\n");
    }

    else
    {
    print(
    " <!-- No name has been provided, so we
     prompt the user for one. -->"
    );

    print(
    " <FORM ACTION = $PHP_SELF METHOD = POST><br>\n");
    print(
    " Please enter your first name: <INPUT TYPE = TEXT  NAME = \"firstname\"><br>\n");
    print(
    " Please enter your surname: <INPUT TYPE = TEXT  NAME = \"surname\"><br>\n");
    print(
    " Please enter your userid: <INPUT TYPE = TEXT  NAME = \"userid\"><br>\n");
    print(
    " Please enter your password: <INPUT TYPE = PASSWORD  NAME = \"password\"><br>\n");
    print(
    " <INPUT TYPE = SUBMIT VALUE = \"GO\">\n");
    print(
    " </FORM><br>\n");


    }
    ?>
    </body>
    </html>

    Here is the script that handles output from the script:

    <html>
    <Head>
    <title>Sample Page</title>
    </Head>
    <body>
    PHP Code:
    <?php
    $Host 
    "**********";// Set the variables for the database access:
    $User "******";
    $MasterPassword "******";       
    $DBName "*****";     
    $TableName "personaldetails";

    $link = @mysql_connect("$Host""$User""$MasterPassword");
    if (!
    $link)
     {
     print(
    "<P>Unable to connect to the " .       
     
    "database server at this time.</P>\n");      
    exit();
    }

    if (! @
    mysql_select_db($DBName) )
     {
     print(
    "<P>Unable to locate the $DBName database at this time.</P>\n");
     exit();
     } 
    $Array=explode(" ",$logondetails);

    $Query="SELECT * FROM $TableName WHERE password='$Array[1]' AND userid='$Array[0]'";
    $Result=mysql_query ($Query) or die(mysql_error());
    $num_rows=mysql_num_rows($Result);
    $Row mysql_fetch_array ($Result);

    if(
    $num_rows==1
    {
     if(
    $Row['teacherstatus']=='Y')
      {
      
    $Newstring=implode(" ",$Array);
      
    $logondetails=urlencode($Newstring);
      
    $name=urlencode($name);
      
    header("Location: teacher.php?UserName=$name&logondetails=$logondetails");
      exit();
      }

        else
          {
          
    $Newstring=implode(" ",$Array);
          
    $logondetails=urlencode($Newstring);
          
    $name=urlencode($name);
          
    header ("Location: student.php?UserName=$name&logondetails=$logondetails");
          exit();
          }
    }

    header ("Location: firstpage5.php?Message=Invalid");
    exit();         


    mysql_close ($link);

    ?>
    <\body>
    <\html>

    Here is the teacher.php script:
    <html>
    <head>
    <title>The teacher page</title>
    </head>
    <body>
    [php]
    <?php

    $Array=explode(" ", $name);
    $UserName=$Array[0] . " " . $Array[1];

    print("Greetings " . $UserName . "<br>\n");
    ?>
    [php]
    </body>
    </html>

    Is it something simple?

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

    solved

    I was exploding $name when I should have been exploding $UserName - also I started to get problems with headers already sent - this was because I forgot nothing, even the title, must go to the browser before the header. Oh well, alright now.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW

    PHP Code:
    $Array=explode(" "$name); 
    $UserName=$Array[0] . " " $Array[1]; 
    What is this all about? There is no need, you can simply use

    print urldecode($UserName);
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

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

    Thanks

    Yes, that is somewhat easier. I didn't know about its existance. I shall try it out.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are all sorts of neat little functions for manipulating text. Have a look

    http://www.php.net/strings
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

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

    Thanks

    Thanks
    While, your online, can I get one more question in. I wish to sum the contents in the score column of my table. The php manual would seem to suggest there is no sum() function - I'm never too sure how much sql you can use when your basic language is php? There is an array_sum(array)in php or can I just use sum(). Also the coumn cotains test marks for several different types of test eg Chemistry and Physics. Do I add up scores for different tests by putting a group by testname (thats the column name that has the name of the test)in the query.

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT testname, SUM(ScoreColumn) as ScoreTotal from table name GROUP BY testname


    This is a basic example and should do the trick.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •