我有一個數據庫'School'。它只有一個表格 - 'Words'。其中有word_id,word_name,word_description。我想拉一個隨機的描述並將其顯示在頁面上。然後,我想輸入一個單詞並查看該單詞是否與隨機單詞具有相同的描述。我究竟做錯了什麼?這裏的代碼 -之後在select語句中使用MySQL隨機行
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Изпит</title>
</head>
<body>
<?php
$connection = mysqli_connect('localhost', 'root', '', 'school');
if(!$connection){
echo 'NOT OK';
exit;
}
if(isset($_POST['submit_description'])){
$q = mysqli_query($connection, ' SELECT word_description
FROM words ORDER BY rand() LIMIT 1
');
$row=mysqli_fetch_assoc($q);
if($row){
$_POST['word_description'] = $row['word_description'];
echo $_POST['word_description'];
}
}
if(isset($_POST['submit_word'])){
$word_name = $_POST['word_name'];
$q2="SELECT * FROM words WHERE word_name='$word_name' and word_description='".$_POST['word_decsription']."'";
$result=mysqli_query($connection, $q2);
$count=mysqli_num_rows($result);
if($count==1){
echo 'Позна ве.';
}else{
echo 'Не позна ве.';
}
}
?>
<br><br><br>
<form method="POST">
<input type="submit" name="submit_description" value="Искай описание.">
<input type="hidden" name="word_description" value="<?php echo $_POST['word_description']?>">
</form>
<form method="POST">
<input type="text" name="word_name">
<input type="submit" name="submit_word" value="Провери дума.">
</form>
</body>
</html>
在打開'<?php'標記後立即向文件頂部添加錯誤報告 'error_reporting(E_ALL); ini_set('display_errors',1);'看看它是否產生任何東西。還有'或者死(mysqli_error($連接))'到'mysqli_query()'。 – 2014-11-03 19:20:20
'word_decsription'!='word_description' – 2014-11-03 19:21:08
^^^良好的發現,如果操作系統正在使用它,那麼數據庫方面的錯誤報告和檢查就會發現。 – 2014-11-03 19:22:20