Below is my code. In the first half of my code you will see the variables $question and $row. When I echo $question and/or $row[0] I get values returned. However, at the bottom of the code I try to use these to variables as actual arguments in the add_textbox function. However, the add_textbox function is acting like those variables are null. Can someone tell me what I am doing wrong.
<?php
$dbhost = 'localhost';
$uname = $_POST["uname"];
//***create connection object
$connection = mysql_connect($dbhost, "bc572482", "dfdfdfs")
or die (mysql_error());
$dbname = "bc57";
mysql_select_db($dbname)
or die (mysql_error());
//***select a random security question
//*** need this to import session variables
session_start();
// echo ($_SESSION["ValidUser"] . '<br>');
$uname =$_SESSION["ValidUser"];
//echo ($uname . '<br>');
$rq = array('q1','q2','q3');
$rand_key = array_rand($rq,1);
// echo $rq[$rand_key];
$question = $rq[$rand_key];
$qtoanswer = mysql_query("select $question from users where uname = '$uname'");
if(!$qtoanswer)
{
echo "Could not run query:" . mysql_error();
exit;
}
//echo ($qtoanswer . '<br>');
$row = mysql_fetch_row($qtoanswer);
//echo ($row[0] . abc);
display_security();
//functions to create security page
function myprint($text)
{
print("$text
");
}
//*** a bit of style
function add_style()
{
myprint("<link rel=\"stylesheet\" type=\"text/css\" href= \"main.css\" />");
//myprint("<style type=text/css> * {font-family:arial;} h3 {color:orange} </style>");
}
//*** add a text box
function add_textbox($label, $name)
{
myprint("$label <br><input type=text name=$name><br>");
}
function add_submit($label)
{
myprint("<input type=submit name=submit value=$label>");
myprint("<input type=reset value=Reset><br>");
}
//create the dynamic security page
function display_security()
{
myprint("<html><head>");
add_style();
myprint("</head><body>");
myprint("<h3> Feeding our Brothers and Sisters <br> Security Check</h3>");
// get the security form created
myprint("<form name=securityForm method=post action=login.php>");
add_textbox($row[0],$question);
add_submit("Login");
myprint("</form>");
myprint("</body></html>");
}
?>