以下是我的代码。在我的代码的前半部分,您将看到变量$ question和$ row。当我回显$ question和/或$ row [0]时,我得到了返回的值。但是,在代码的底部我尝试将这些变量用作add_textbox函数中的实际参数。但是,add_textbox函数的作用就像那些变量为null。有人能告诉我我做错了什么。
<?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());
// ***选择随机安全问题
//*** 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 \n");
}
//*** 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>");
}
&GT;
答案 0 :(得分:1)
在调用此$row[0]
函数时,将$question
和display_security()
作为函数参数传递
display_security($row[0], $question);
在display_security()
中使用参数变量$p
&amp; $question
function display_security($p, $question)
{
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($p,$question);
^^^ ^^^^^^^^
add_submit("Login");
myprint("</form>");
myprint("</body></html>");
}
答案 1 :(得分:0)