我试图从我的数据库中选择并显示有关记录的一些信息 选择用户/名称/记录并按Afiseaza(提交)后,页面保持不变,就像不刷新一样。
我无法找到问题所在。这是我的代码:
<?php
include 'ch20_include.php';
doDB();
if('!_POST') {
//Arata
$display_block = "<h1>Alege un Elev</h1>";
//Primeste partile
$get_list_sql = "SELECT id,CONCAT_WS(', ', nume,p_nume) AS display_name FROM nume_principal ORDER BY p_nume,nume";
$get_list_res = mysqli_query($mysqli,$get_list_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rowS($get_list_res) < 1) {
//Nici un elev
$display_block .= "<p><em>Scuze,nu a fost selectat nici un Elev!</em></p>";
} else {
//Afiseaza
$display_block .= "
<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\"/>
<p><label for=\"sel_id\">Alege un Elev:</label><br/>
<select id='sel_id\' name=\"sel_id\" required=\"required\">
<option value=\"\">--Alege--</option>";
while ($recs = mysqli_fetch_array($get_list_res)) {
$id = $recs['id'];
$display_name = stripslashes($recs['display_name']);
$display_block .= "<option value=\"".$id."\">".$display_name."</option>";
}
$display_block .= " </select> <button type=\"submit\" name=\"submit\" value=\"view\">Afiseaza\"></button>
</form> ";
}
//rezultate
mysqli_free_result($get_list_res);
} else if($_POST) {
//Verifica field
if ($_POST['sel_id'] == "") {
header("Location: seldata.php");
exit;
}
//Versiune sigura ID
$safe_id = mysqli_real_escape_string($mysqli, $_POST['sel_id']);
$get_nume_sql = "SELECT concat_ws(' ',p_nume,nume) as display_name FROM nume_principal WHERE id = '".$safe_id."'";
$get_nume_res = mysqli_query($mysqli, $get_nume_sql) or die(mysqli_error($mysqli));
while ($nmae_info = mysqli_fetch_array($get_nume_res)) {
$display_name = stripslashes($name_info['display_name']);
}
$display_block = "<h1>Arata Informatile pentru ".$display_name."</h1>";
mysqli_free_result($get_nume_res);
//Adresa
$get_adresele_sql = "SELECT adresa,oras,judet,cod_postal FROM adress WHERE nume_id = '".$safe_id."'";
$get_adresele_res = mysqli_query($mysqli, $get_adresele_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_adresele_res) > 0) {
$display_block .= "<p><strong>Adresa:</strong><br/><ul>";
while ($add_info = mysqli_fetch_array($get_adresele_Res)) {
$adresa = stripslashes($add_info['adresa']);
$oras = stripslashes($add_info['oras']);
$judet = stripslashes($add_info['oras']);
$cod_postal = stripslashes($add_info['cod_postal']);
$display_block .= "<li>$adresa,$oras,$judet,$cod_postal</li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_adresele_res);
//telefon
$get_tel_sql = "SELECT tel_numar,type FROM telefon WHERE nume_id = '".$safe_id."'";
$get_tel_res = mysqli_query($mysqli, $get_tel_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_tek_res) > 0) {
$display_block .= "<p><strong>Telefon:</stron><br/> <ul>";
while ($tel_info = mysqli_fetch_array($get_tel_res)) {
$tel_numar = stripslashes($tel_info['tel_numar']);
$tel_type = $tel_info['type'];
}
$display_block .= "</ul>";
}
mysqli_free_result($get_tel_res);
//Adresele toate
$get_biologie_sql = "SELECT notab_1, notab_2, notab_3, notab_4, notab_5, medieb FROM biologie WHERE nume_id = '".$safe_id."'";
$get_biologie_res = mysqli_query($mysqli, $get_biologie_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_biologie_res) > 0 ) {
$display_block .= "<p><strong>Note-Biologie:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_biologie_res)) {
$notab_1 = stripslashes($add_info['notab_1']);
$notab_2 = stripslashes($add_info['notab_2']);
$notab_3 = stripslashes($add_info['notab_3']);
$notab_4 = stripslashes($add_info['notab_4']);
$notab_5 = stripslashes($add_info['notab_5']);
$medieb = stripslashes($add_info['medieb']);
$display_block .= "<li>$notab_1 $notab_2 $notab_3 $notab_4 $notab_5 $medieb </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_biologie_res);
$get_chimie_sql = "SELECT notac_1, notac_2, notac_3, notac_4, notac_5, mediec FROM chimie WHERE nume_id = '".$safe_id."'";
$get_chimie_res = mysqli_query($mysqli, $get_chimie_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_chimie_res) > 0 ) {
$display_block .= "<p><strong>Note-Chimie:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_chimie_res)) {
$notac_1 = stripslashes($add_info['notac_1']);
$notac_2 = stripslashes($add_info['notac_2']);
$notac_3 = stripslashes($add_info['notac_3']);
$notac_4 = stripslashes($add_info['notac_4']);
$notac_5 = stripslashes($add_info['notac_5']);
$mediec = stripslashes($add_info['mediec']);
$display_block .= "<li>$notac_1 $notac_2 $notac_3 $notac_4 $notac_5 $mediec </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_chimie_res);
$get_fizica_sql = "SELECT notaf_1, notaf_2, notaf_3, notaf_4, notaf_5, medief FROM fizica WHERE nume_id = '".$safe_id."'";
$get_fizica_res = mysqli_query($mysqli, $get_fizica_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_fizica_res) > 0 ) {
$display_block .= "<p><strong>Note-Fizica:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_fizica_res)) {
$notaf_1 = stripslashes($add_info['notaf_1']);
$notaf_2 = stripslashes($add_info['notaf_2']);
$notaf_3 = stripslashes($add_info['notaf_3']);
$notaf_4 = stripslashes($add_info['notaf_4']);
$notaf_5 = stripslashes($add_info['notaf_5']);
$medief = stripslashes($add_info['medief']);
$display_block .= "<li>$notaf_1 $notaf_2 $notaf_3 $notaf_4 $notaf_5 $medief </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_fizica_res);
$get_franceza_sql = "SELECT notafr_1, notafr_2, notafr_3, notafr_4, notafr_5, mediefr FROM franceza WHERE nume_id = '".$safe_id."'";
$get_franceza_res = mysqli_query($mysqli, $get_franceza_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_franceza_res) > 0 ) {
$display_block .= "<p><strong>Note-Franceza:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_franceza_res)) {
$notafr_1 = stripslashes($add_info['notafr_1']);
$notafr_2 = stripslashes($add_info['notafr_2']);
$notafr_3 = stripslashes($add_info['notafr_3']);
$notafr_4 = stripslashes($add_info['notafr_4']);
$notafr_5 = stripslashes($add_info['notafr_5']);
$mediefr = stripslashes($add_info['mediefr']);
$display_block .= "<li>$notafr_1 $notafr_2 $notafr_3 $notafr_4 $notafr_5 $mediefr </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_franceza_res);
$get_germana_sql = "SELECT notag_1, notag_2, notag_3, notag_4, notag_5, medieg FROM germana WHERE nume_id = '".$safe_id."'";
$get_germana_res = mysqli_query($mysqli, $get_germana_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_germana_res) > 0 ) {
$display_block .= "<p><strong>Note-Germana:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_germana_res)) {
$notag_1 = stripslashes($add_info['notag_1']);
$notag_2 = stripslashes($add_info['notag_2']);
$notag_3 = stripslashes($add_info['notag_3']);
$notag_4 = stripslashes($add_info['notag_4']);
$notag_5 = stripslashes($add_info['notag_5']);
$medieg = stripslashes($add_info['medieb']);
$display_block .= "<li>$notag_1 $notag_2 $notag_3 $notag_4 $notag_5 $medieg </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_germana_res);
$get_informatica_sql = "SELECT notai_1, notai_2, notai_3, notai_4, notai_5, mediei FROM informatica WHERE nume_id = '".$safe_id."'";
$get_informatica_res = mysqli_query($mysqli, $get_informatica_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_informatica_res) > 0 ) {
$display_block .= "<p><strong>Note-Informatica:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_informatica_res)) {
$notai_1 = stripslashes($add_info['notai_1']);
$notai_2 = stripslashes($add_info['notai_2']);
$notai_3 = stripslashes($add_info['notai_3']);
$notai_4 = stripslashes($add_info['notai_4']);
$notai_5 = stripslashes($add_info['notai_5']);
$mediei = stripslashes($add_info['mediei']);
$display_block .= "<li>$notai_1 $notai_2 $notai_3 $notai_4 $notai_5 $mediei </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_matematica_res);
$get_matematica_sql = "SELECT notam_1, notam_2, notam_3, notam_4, notam_5, mediem FROM matematica WHERE nume_id = '".$safe_id."'";
$get_matematica_res = mysqli_query($mysqli, $get_matematica_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_matemtica_res) > 0 ) {
$display_block .= "<p><strong>Note-Matematica:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_matematica_res)) {
$notam_1 = stripslashes($add_info['notam_1']);
$notam_2 = stripslashes($add_info['notam_2']);
$notam_3 = stripslashes($add_info['notam_3']);
$notam_4 = stripslashes($add_info['notam_4']);
$notam_5 = stripslashes($add_info['notam_5']);
$mediem = stripslashes($add_info['mediem']);
$display_block .= "<li>$notam_1 $notam_2 $notam_3 $notam_4 $notam_5 $mediem </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_matematica_res);
$get_romana_sql = "SELECT notar_1, notar_2, notar_3, notar_4, notar_5, medier FROM romana WHERE nume_id = '".$safe_id."'";
$get_romana_res = mysqli_query($mysqli, $get_romana_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_romana_res) > 0 ) {
$display_block .= "<p><strong>Note-Romana:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_romana_res)) {
$notar_1 = stripslashes($add_info['notar_1']);
$notar_2 = stripslashes($add_info['notar_2']);
$notar_3 = stripslashes($add_info['notar_3']);
$notar_4 = stripslashes($add_info['notar_4']);
$notar_5 = stripslashes($add_info['notar_5']);
$medier = stripslashes($add_info['medier']);
$display_block .= "<li>$notar_1 $notar_2 $notar_3 $notar_4 $notar_5 $medier </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_romana_res);
$get_religie_sql = "SELECT notare_1, notare_2, notare_3, notare_4, notare_5, mediere FROM religie WHERE nume_id = '".$safe_id."'";
$get_religie_res = mysqli_query($mysqli, $get_religie_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_religie_res) > 0 ) {
$display_block .= "<p><strong>Note-Religie:</strong><br/> <ul>";
while ($add_info = mysqli_fetch_array($get_religie_res)) {
$notare_1 = stripslashes($add_info['notare_1']);
$notare_2 = stripslashes($add_info['notare_2']);
$notare_3 = stripslashes($add_info['notare_3']);
$notare_4 = stripslashes($add_info['notare_4']);
$notare_5 = stripslashes($add_info['notare_5']);
$mediere = stripslashes($add_info['medieb']);
$display_block .= "<li>$notare_1 $notare_2 $notare_3 $notare_4 $notare_5 $mediere </li>";
}
$display_block .= "</ul>";
}
mysqli_free_result($get_religie_res);
//Nota personala
$get_notes_sql = "SELECT note FROM nota_personala WHERE nume_id = '".$safe_id."'";
$get_notes_res = mysqli_query($mysqli, $get_notes_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_notes_res) == 1) {
while ($note_info = mysqli_fetch_array($get_notes_res)) {
$note = n12br(stripslashes($note_info['note']));
}
$display_block .= "<p><strong>Nota personala:</strong><br/> $note</p>";
}
mysqli_free_result($get_notes_res);
$display_block .= "<br/>
<p style=\"text-align:center\">
<a href=\"".$_server['PHP_SELF']."\">Alege altul</a></p>";
}
mysqli_close($mysqli);
?>
<!DOCTYPE html>
<html>
<head>
<title>Elevii</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>
答案 0 :(得分:1)
首先你的代码错了!_POST不能像字符串一样使用,因为
“如果对任何非零元素返回true”
,所以改变它
if(!$_POST) or if($_SERVER['REQUEST_METHOD']!='POST')