PHP and XML - using hidden forms as variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamace5o
    New Member
    • Feb 2008
    • 3

    PHP and XML - using hidden forms as variables

    hi, i am trying to use a hidden form as a method of storing varibles for use throughout an online quiz site.

    I am using mysql to hold data about the users ie user id username and user password etc.

    The information is input into a visible form and then when the user clicks the submit button, a validatelogin.p hp script is run which takes the data from the input and checks it against the mysql database.

    I want to know if there is a way of taking the data from one form, running it thorugh this php script below and then assigning the data from the php variables to the hidden form?

    here is the php file:

    <?php


    session_start() ;



    $host="localhos t"; // Host name
    $username="root "; // Mysql username
    $password="xxxx xxxxx"; // Mysql password
    $db_name="test" ; // Database name
    $tbl_name="Stud ent"; // Table name

    // Connect to server and select databse.
    mysql_connect(" $host", "$username" , "$password" )or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

    // username and password sent from signup form
    $myusername=$_P OST['studentusernam e'];
    $mypassword=$_P OST['studentpasswor d'];

    //HERE I WANT TO ASSIGN $myusername and $mypassword to the fields in the hidden form called 'hiddenuser' and 'hiddenpassword '


    $_SESSION['user']=$myusername;


    $sql="SELECT * FROM $tbl_name WHERE userName='$myus ername' and userPassword='$ mypassword'";
    $result=mysql_q uery($sql);

    // Mysql_num_row is counting table row
    $count=mysql_nu m_rows($result) ;
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){

    session_registe r("studentusern ame");
    session_registe r("studentpassw ord");
    header("locatio n:welcome.xml") ;

    }
    else {

    header("locatio n:failedlogin.x ml");

    }


    ?>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    If you are talking about filling a couple of 'normal' input text fields, you can just put the variable names in the input statement, like:
    [php]
    echo "<input type='hidden' name='uid' value='$myusern ame' />"
    echo "<input type='hidden' name='psw' value='$mypassw ord' />"
    [/php]

    But I only wonder why you do not use the $_SESSION array to carry these variables between different pages?

    Ronald

    Comment

    • adamace5o
      New Member
      • Feb 2008
      • 3

      #3
      Originally posted by ronverdonk
      If you are talking about filling a couple of 'normal' input text fields, you can just put the variable names in the input statement, like:
      [php]
      echo "<input type='hidden' name='uid' value='$myusern ame' />"
      echo "<input type='hidden' name='psw' value='$mypassw ord' />"
      [/php]

      But I only wonder why you do not use the $_SESSION array to carry these variables between different pages?

      Ronald
      I cant seem to use the $_session variable. I am using xml so i am going from index.xml with the login to validatelogin.p hp to check the crudentials against mysql database and then moving to welcome.xml. i am new to this and support for this combination of xml and php seems sparse.

      il try your first suggestion

      thanks

      Adam

      when i say xml i should be saying i have xml files that are transformed by an xsl sheet and then styled using a css. I want the php files to provide my intereation with the database and offer me access to this dynamic data.

      Comment

      Working...