我使用$ GLOBALS来全局化变量data3,reg,kok和random ..但是当我运行代码时,它只是显示未定义的变量。
我到处都在寻找答案,但找不到任何东西。
<?php
if (isset($_POST['kraje'])){
$globals['$reg'] = $_POST['kraje'];
echo $reg;
}
if (isset($_POST['okresi'])) {
$GLOBALS['$kok'] = $_POST['okresi'];
echo $kok;
}
// volba okresů
function okresi(){
$connection = mysqli_connect("localhost", "root", "", "uzemnicelkycr");
mysqli_set_charset($connection,"utf8");
$sql = 'SELECT nazev, id FROM okres';
$res = mysqli_query($connection, $sql);
$data = array();
$adata = array();
echo "Volba okresu: ";
echo "<select name='okresi'>";
if (mysqli_num_rows($res) > 0) {
while ($row = mysqli_fetch_assoc($res)) {
$data[] = $row['nazev'];
$adata[] = $row['id'];
echo '<option value=" '.$row['id'].'">'.$row['nazev'].'</option>';
}
}
echo "</select> ";
}
//volba krajů
function kraje(){
$connection = mysqli_connect("localhost", "root", "", "uzemnicelkycr");
mysqli_set_charset($connection,"utf8");
$sqn = 'SELECT nazev, id FROM kraj';
$data2 = array();
$adata2 = array();
$resolution = mysqli_query($connection, $sqn);
echo "Volba kraje: ";
echo "<select name='kraje'>";
if(mysqli_num_rows($resolution) > 0){
while ($rows = mysqli_fetch_assoc($resolution)) {
$adata2[] = $rows['id'];
$data2[] = $rows['nazev'];
echo '<option value=" '.$rows['id'].'" >'.$rows['nazev'].'</option>';
}
}
echo "</select>";
}
//náhodná obec
function pick(){
$connection = mysqli_connect("localhost", "root", "", "uzemnicelkycr");
mysqli_set_charset($connection,"utf8");
$sin = 'SELECT kraj_id, okres_id, nazev FROM obec';
$reso = mysqli_query($connection, $sin);
$GLOBALS['$data3'] = array();
if (mysqli_num_rows($reso) > 0) {
while($rowss = mysqli_fetch_array($reso,MYSQL_ASSOC)){
$data3[] = $rowss;
}
}
$GLOBALS['$random'] = array_rand ($data3);
echo $data3[$GLOBALS['$random']]['nazev'];
}
//kontrola
function control($data3, $reg, $kok, $random){
if($data3[$random]['kraj_id'] == $reg && $data3[$random]['okres_id'] = $kok){
echo "Výhra";
}
else{
echo "Špatně";
}
}
control($data3, $reg, $kok, $random);
?>
注意:未定义的变量:C:\ Program Files(x86)\ EasyPHP-Devserver-17 \ eds-www \ MySQLProject \ functions.php在第88行中的数据3
通知:未定义的变量:C:\ Program Files(x86)\ EasyPHP-Devserver-17 \ eds-www \ MySQLProject \ functions.php在第88行上的reg
注意:未定义的变量:在第88行上的C:\ Program Files(x86)\ EasyPHP-Devserver-17 \ eds-www \ MySQLProject \ functions.php中的角点
注意:未定义的变量:C:\ Program Files(x86)\ EasyPHP-Devserver-17 \ eds-www \ MySQLProject \ functions.php在第88行随机存在