在我的程序中,我试图获取表单提交的值并在 sql 查询中使用以检索结果,然后再次使用 $_GET["name"] 值将数据提供给数据库。以下代码未在 while 循环 $_GET["name"] 内传播值
<?php
session_start();
$id = $_GET["name"];
echo "<h2> Hello ".$id." </h2>" ;
if((isset( $_POST['dept'])))
{
echo "<h2><center>You have sected ". $_POST['dept'] ." !!</center></h2>";
$dept_ = $_POST['dept'];
$options = $_POST['course'];
foreach($options as $option) //loop through the checkboxes
{
$uid="root";
$pass="root";
$db = mysql_connect("localhost:3036",$uid,$pass);
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db("sync" ,$db);
$result = mysql_query("SELECT DISTINCT `name`,`password`,INET_NTOA( `ip` ) FROM detail Where id = '$_GET["name"]' ;") or die(mysql_error());
if(mysql_num_rows($result) > 0):
while($row = mysql_fetch_assoc($result)):
$name = $row['name'];
$password = $row['password'];
$ip = $row['INET_NTOA( `ip` )'];
echo $name ; // NOT PRINTING ANYTHING
echo $password ; // NOT PRINTING ANYTHING
echo $_GET["name"] ; // NOT PRINTING ANYTHING
$sql1_Qu = "INSERT INTO registration (id,password,ip,name,course) VALUES ('$_GET["name"]','$password',INET_ATON('$ip'),'$name','$option')";
//$sql1_Qu = "INSERT INTO registration (id,password,ip,name,course) VALUES ('$id','$password',INET_ATON('$ip'),'$name','$option')";
$resu = mysql_query($sql1_Qu) or die('Could not connect: ' . mysql_error());
endwhile;
endif;
}
}
?>
这仅在第 4 行打印,但不传播包含数据库查询的 while 循环内的值。
请提出一些解决问题的方法......在此先感谢