Php 未在页面之间传递会话变量值
我对php有点陌生,尽管在这段代码让我感到困惑之前,我已经设法传递了会话变量的值Php 未在页面之间传递会话变量值,php,Php,我对php有点陌生,尽管在这段代码让我感到困惑之前,我已经设法传递了会话变量的值 <form action="team_reg2.php" method="post" name="form1" class="cent" id="form1"> <p><strong>Team Registration</strong></p> <?php $con=mysql_connect("localhost","root","");
<form action="team_reg2.php" method="post" name="form1" class="cent" id="form1">
<p><strong>Team Registration</strong></p>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("databolism",$con);
$result=mysql_query("select * from events where id=$_POST[event]",$con);
$row=mysql_fetch_assoc($result);
$num=$row['max_team'];
$_SESSION['max_team']=$num;
$_SESSION['event_id']=$_POST['event'];
for($i=1;$i<=$num;$i++)
{
print "<p><span id=\"sprytextfield$i\"\n>";
print "<label>member$i";
print "<input type=\"text\" name=\"mem$i\" id=\"mem$i\" />\n";
print "</label>\n";
print "<span class=\"textfieldInvalidFormatMsg\">Please enter only id</span></span></p>\n";
}
?>
团队注册
现在,这将通过post传递到team_reg2.php
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
die("could not connect to db");
$db=mysql_select_db("databolism",$con);
$num=6;
$event=14;
$result=mysql_query("select * from events where id=$event",$con) or die(mysql_error());
$row=mysql_fetch_assoc($result);
$query='fantasia1_'.$row['name'];
$query2="select max(t_id) from $query";
$que=mysql_query($query2,$con);
$result=mysql_fetch_array($que) or die(mysql_error());
$chk3=$result['max(t_id)'];
if($chk3==NULL)
{
for($i=1;$i<=$num;$i++)
{
$name='mem'.$i;
if($_POST["$name"]!="")
{
$query2="insert into $query values(1,'$_POST[$name]')";
$que=mysql_query($query2,$con);
}
}
echo " please note your team id is 1 <br>";
echo " your team members are : <br>";
for($i=1;$i<=$num;$i++)
{
$name='mem'.$i;
echo "$_POST[$name]<br>";
}
}
else
{
$str="select * from $query where (";
for($i=1;$i<=$num;$i++)
{
$name='mem'.$i;
$text="p_id='$_POST[$name]'";
if($i==1)
$str=$str.$text;
else
$str=$str.' or '.$text;
}
$str=$str.')';
$query2=$str;
echo "$str<br>";
// echo "$query2</br>";
$que=mysql_query($query2,$con) or die(mysql_error());
$num=mysql_num_rows($que);
if($num!=0)
{
while($result=mysql_fetch_array($que))
{
echo "$result[p_id] is already registered in team $result[t_id]<br>";
}
//include("reg_team.html");
}
else if($num==0)
{
//echo $query;
$query2="select max(t_id) from $query";
$que=mysql_query($query2,$con) or die(mysql_error());
//echo "$que<br>";
$result=mysql_fetch_array($que);
$max=$result['max(t_id)'];
$max++;
$num=$_SESSION['max_team'];
for($i=1;$i<=$num;$i++)
{
$name='mem'.$i;
if($_POST[$name]!="")
{
$query2="insert into $query values($max,'$_POST[$name]')";
$que=mysql_query($query2,$con);
}
}
echo " please note your team id is $max <br>";
echo " your team members are : <br>";
for($i=1;$i<=$num;$i++)
{
$name='mem'.$i;
echo "$_POST[$name]<br>";
}
}
}
?>
第二个文件中也需要session\u start()
。第二个文件中也需要session\u start()
。第二页上的session\u start()
也用过吗?顺便提一下,要小心SQL注入。我在代码中发现了一个(可能还有更多)。您是否也使用了第二页上的session\u start()
?顺便提一下,请注意SQL注入。我在代码中发现了一个(可能还有更多)。我在第二个文件中使用了session_start,你可以回显$num的值吗?我认为你的else if条件可能是错误的。我在第二个文件中使用session_start,你可以回显$num的值吗?我认为你的else if条件可能是错误的。