2016-04-25 109 views
-1

是我的html代碼和PHP函數是這樣的,我可以查詢所有問題從數據庫與php mysql_fetch_assoc但不能計算真正的或空的,有效的答案與PHP if(isset($ _ POST function 。我不知道該怎麼做,如果isset功能以及如何計算所有的答案單選按鈕,如果isset功能不工作

<html lang="tr_TR"> 
 

 
<head> 
 

 
    <meta charset="utf-8"> 
 

 
    <title>test</title> 
 

 
</head> 
 

 
<body> 
 

 
    <form action="" method=POST> 
 
    
 
    <?PHP 
 
require_once('a/baglanti.php'); 
 

 
$sql = "SELECT id as id, soru,a,b,c,d,dcevap,tarih,sorugrup FROM sorular 
 
WHERE yayinla = 'Evet' order by tarih "; 
 

 
$result = mysql_query($sql); 
 

 
if (!$result) { 
 
    echo "Could not successfully run query ($sql) from DB: " . mysql_error(); 
 
    exit; 
 
} 
 

 
if (mysql_num_rows($result) == 0) { 
 
    echo "No rows found, nothing to print so am exiting"; 
 
    exit; 
 
} 
 

 
while ($row = mysql_fetch_assoc($result)) { 
 
    
 
$id=$row['id']; 
 
$soru=$row['soru']; 
 
$a=$row['a']; 
 
$b=$row['b']; 
 
$c=$row['c']; 
 
$d=$row['d']; 
 
$dcevap=$row['dcevap']; 
 
$sorugrup=$row['sorugrup']; 
 
//all records 
 

 
?> 
 
<?php echo "$id"; ?> <?php echo "$soru"; ?> 
 
<p><?php echo "$a"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="a"></p> 
 
<p><?php echo "$b"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="b"></p> 
 
<p><?php echo "$c"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="c"></p> 
 
<p><?php echo "$d"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="d"></p> 
 
<?php 
 
} 
 
mysql_free_result($result); 
 
?> 
 
<p></p> 
 
<p></p> 
 
      <input type="submit" value="HESAPLA" name="btn"><br> 
 
     </p> 
 
    </form> 
 
    <?php 
 
     if (isset($_POST['$sorugrup'])) { 
 
      $soru1=$_POST['$sorugrup']; 
 

 
      $d=0; 
 

 
      $y=0; 
 
\t \t \t 
 
\t \t \t $b=0; 
 

 

 

 
\t \t \t 
 

 
      if($soru1=="$dcevap"){ 
 

 
       $c1="DOĞRU"; 
 

 
       $d=$d+1; 
 

 
      } 
 
\t \t \t 
 
\t \t \t elseif(empty($soru1)){ 
 
\t \t \t \t 
 
\t \t \t \t $c1="boş"; 
 

 
       $b=$b+1; 
 
\t \t \t \t 
 
\t \t \t \t } 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t else { 
 

 
       $c1="YANLIŞ"; 
 

 
       $y=$y+1; 
 

 
      } 
 

 
      $d2=$d-1; 
 
\t \t \t $puan=$d*3.3; 
 

 
      echo"Doğru sayısı=$d<br>"; 
 

 
      echo"Yanlış sayısı=$y<br>"; 
 
\t \t \t 
 
\t \t \t echo"Boş sayısı=$b<br>"; 
 
\t \t \t 
 
\t \t \t echo"Aldığınız Puan $puan<br>"; 
 

 
     } 
 

 
    ?> 
 
    
 
</body> 
 

 
</html>

回答

0

這是無效的HTML:

<input type="radio" name="soru[".$id."]" value="a"> 
         ^-----^ - attribute name="soru 
           ^^^^^--- invalid/illegal html 
            ^-^ - unammed/illegal attribute 

由於您的HTML無效,無線電覆選框將發送回服務器的事情是soru = a,而不是soru42 = a或任何ID值應該是。

可能是代碼應該更像

<input type="radio" name="soru[<?php echo $id ?>]" value="a"> 
           ^^^^^^^^^^^^^^^^^ 
0

是我的HTML代碼和PHP函數是這樣的,我可以查詢從數據庫和PHP mysql_fetch_assoc所有問題,但不能計算與PHP的真實的或空的,有效回答如果(isset($ _ POST function.i不知道該怎麼做,如果isset功能以及如何計算所有的答案?

<html lang="tr_TR"> 
 

 
<head> 
 

 
    <meta charset="utf-8"> 
 

 
    <title>test</title> 
 

 
</head> 
 

 
<body> 
 

 
    <form action="" method=POST> 
 
    
 
    <?PHP 
 
require_once('a/baglanti.php'); 
 

 
$sql = "SELECT id as id, soru,a,b,c,d,dcevap,tarih,sorugrup FROM sorular 
 
WHERE yayinla = 'Evet' order by tarih "; 
 

 
$result = mysql_query($sql); 
 

 
if (!$result) { 
 
    echo "Could not successfully run query ($sql) from DB: " . mysql_error(); 
 
    exit; 
 
} 
 

 
if (mysql_num_rows($result) == 0) { 
 
    echo "No rows found, nothing to print so am exiting"; 
 
    exit; 
 
} 
 

 
while ($row = mysql_fetch_assoc($result)) { 
 
    
 
$id=$row['id']; 
 
$soru=$row['soru']; 
 
$a=$row['a']; 
 
$b=$row['b']; 
 
$c=$row['c']; 
 
$d=$row['d']; 
 
$dcevap=$row['dcevap']; 
 
$sorugrup=$row['sorugrup']; 
 
//all records 
 

 
?> 
 
<?php echo "$id"; ?> <?php echo "$soru"; ?> 
 
<p><?php echo "$a"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="a"></p> 
 
<p><?php echo "$b"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="b"></p> 
 
<p><?php echo "$c"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="c"></p> 
 
<p><?php echo "$d"; ?> <input type="radio" name="<?php echo "$sorugrup"; ?>" value="d"></p> 
 
<?php 
 
} 
 
mysql_free_result($result); 
 
?> 
 
<p></p> 
 
<p></p> 
 
      <input type="submit" value="HESAPLA" name="btn"><br> 
 
     </p> 
 
    </form> 
 
    <?php 
 
     if (isset($_POST['$sorugrup'])) { 
 
      $soru1=$_POST['$sorugrup']; 
 

 
      $d=0; 
 

 
      $y=0; 
 
\t \t \t 
 
\t \t \t $b=0; 
 

 

 

 
\t \t \t 
 

 
      if($soru1=="$dcevap"){ 
 

 
       $c1="DOĞRU"; 
 

 
       $d=$d+1; 
 

 
      } 
 
\t \t \t 
 
\t \t \t elseif(empty($soru1)){ 
 
\t \t \t \t 
 
\t \t \t \t $c1="boş"; 
 

 
       $b=$b+1; 
 
\t \t \t \t 
 
\t \t \t \t } 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t else { 
 

 
       $c1="YANLIŞ"; 
 

 
       $y=$y+1; 
 

 
      } 
 

 
      $d2=$d-1; 
 
\t \t \t $puan=$d*3.3; 
 

 
      echo"Doğru sayısı=$d<br>"; 
 

 
      echo"Yanlış sayısı=$y<br>"; 
 
\t \t \t 
 
\t \t \t echo"Boş sayısı=$b<br>"; 
 
\t \t \t 
 
\t \t \t echo"Aldığınız Puan $puan<br>"; 
 

 
     } 
 

 
    ?> 
 
    
 
</body> 
 

 
</html>