By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

PHP and XML - using hidden forms as variables

P: 3
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.php 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="localhost"; // Host name
$username="root"; // Mysql username
$password="xxxxxxxxx"; // Mysql password
$db_name="test"; // Database name
$tbl_name="Student"; // 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=$_POST['studentusername'];
$mypassword=$_POST['studentpassword'];

//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='$myusername' and userPassword='$mypassword'";
$result=mysql_query($sql);

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

if($count==1){

session_register("studentusername");
session_register("studentpassword");
header("location:welcome.xml");

}
else {

header("location:failedlogin.xml");

}


?>
Feb 10 '08 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
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='$myusername' />"
echo "<input type='hidden' name='psw' value='$mypassword' />"
[/php]

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

Ronald
Feb 10 '08 #2

P: 3
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='$myusername' />"
echo "<input type='hidden' name='psw' value='$mypassword' />"
[/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.php 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.
Feb 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.