我是php新手,我制作了一个php,首先获取一个变量并从数据库中找到一个变量(arithmos_ff),然后运行html代码(与aithsh.php代码在同一个文件中)并取一个从它的第二篇文章我想与“arithmos_ff”进行比较。但是在发送后发布第二个变量后显示“Undefined index:arithmos_ff”。 如何保留第一个变量并在第二个帖子完成后使用它? 提前谢谢你!`
<?php
$connect=mysqli_connect('localhost','root','','project');
if($connect->connect_error)
{
die( 'Failed to connect');
}
else {echo 'connect worked';}
$_SESSION['titlos'] = $_GET["value"];//take the first variable
$titlos=$_SESSION['titlos'];
echo"<br>Ο αιτούμενος επιθυμεί να λάβει την διπλωματική με τίτλο ".$titlos ;
$sql2="SELECT ar_foithtwn FROM diplwmatikh WHERE find_in_set('$titlos',title) > 0";
$result3=$connect->query($sql2);
if(mysqli_num_rows($result3)){
while($row1=$result3->fetch_assoc()){
$GLOBALS['arithmos_ff']=$row1['ar_foithtwn'];
//arithmos_ff=i want to keep it!
echo" <br>o arithmos foithtwn pou epitrepetai nanalavoun thn diplwmatikh einai :".$row1['ar_foithtwn'];
}
}
if (isset($_POST['number'])){//this is the second post that get from html
$GLOBALS['arithmos']=$_POST['arithmos'];
check_number();
//and i want to compare 'arithmos' with 'arithmos_ff' in this function
}
function check_number() {//to use it in this function after second post
if( $GLOBALS['arithmos']== $GLOBALS['arithmos_ff']){
echo"<br>Ο αριθμός των φοιτητών που προβλέπεται να την αναλάβουν είναι ο επιθυμητός : ".$GLOBALS['arithmos'] ;
$sql="UPDATE diplwmatikh SET katastash=2 WHERE find_in_set('$titlos',title) > 0";
if(mysqli_query($connect,$sql)){
echo "<br>Update η κατασταση της διπλωματικης σε 2(υπο έγκριση).";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect);
}
}}
?> `
答案 0 :(得分:0)
$GLOBAL
。所以它不再是第二次提交。所以你需要将值存储在SESSION
启动页面顶部的session
session_start();
在此会话中存储
while($row1=$result3->fetch_assoc()){
$_SESSION['arithmos_ff']=$row1['ar_foithtwn'];
//arithmos_ff=i want to keep it!
echo" <br>o arithmos foithtwn pou epitrepetai nanalavoun thn diplwmatikh einai :".$row1['ar_foithtwn'];
}
像这样访问
if (isset($_POST['number'])){
$_SESSION['arithmos']=$_POST['arithmos'];
check_number();
}
功能
function check_number() {
if( $_SESSION['arithmos']== $_SESSION['arithmos_ff']){
......
}
}