2017-05-30 100 views
0

我是新來的PHP,我做了一個PHP,首先得到一個變量,並從數據庫(arithmos_ff)中找到一個變量,然後運行html代碼(它與aithsh在同一個文件中.php代碼),並從它的第二篇文章,我想比較它與「arithmos_ff」。但是在發送第二個變量後顯示「Undefined index:arithmos_ff」。 如何保留第一個變量並在第二個後期完成後使用它? 預先感謝您!`第二次POST後保留全局值

<?php 
 

 
$connect=mysqli_connect('localhost','root','','project'); 
 
    
 
if($connect->connect_error) 
 
{ 
 
\t \t die('Failed to connect'); 
 
} 
 
else {echo 'connect worked';} 
 

 
\t $_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)){ 
 
\t while($row1=$result3->fetch_assoc()){ 
 
\t \t 
 
\t \t $GLOBALS['arithmos_ff']=$row1['ar_foithtwn']; 
 
//arithmos_ff=i want to keep it! 
 
\t \t 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']){ 
 
\t echo"<br>Ο αριθμός των φοιτητών που προβλέπεται να την αναλάβουν είναι ο επιθυμητός : ".$GLOBALS['arithmos'] ; 
 
\t $sql="UPDATE diplwmatikh SET katastash=2 WHERE find_in_set('$titlos',title) > 0"; 
 
if(mysqli_query($connect,$sql)){ 
 
    echo "<br>Update η κατασταση της διπλωματικης σε 2(υπο έγκριση)."; 
 
\t 
 
} else{ 
 
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($connect); 
 
} 
 
}} 
 
\t 
 

 
\t 
 
    
 
?> `

+0

你可以將其保存在會話 – Ghost

+0

我認爲最好使用會話 – JYoThI

回答

0

$GLOBAL將腳本加載的每次重置。所以它是沒有更多的第二次提交。所以你需要將值存儲在會話

開始在頁面頂部

session_start(); 

商店session在會議上這樣

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']){ 

     ...... 
    } 
} 
+0

會議的工作完美!非常感謝您! –

+0

很高興幫助你@marthat – JYoThI