我正在尝试创建一个if else语句,该语句将返回'complete'


I am trying to make an if else statement which will echo 'complete'

我认为问题出在if语句上。我希望代码在数据库中存在testname和学生名的特定值时回显完成,否则显示testname未完成。对于我现在的代码,不管我输入什么testname和name,最后一个echo语句都会出现。

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Quiz results </title>

<?php 
// Created Aug 14th to workout Lesson list to disappear when test is finished
DEFINE ('DB_SERVER', 'localhost');
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PSWD', '');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'ccgate_amendb5');
$dbcon = mysql_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);
$db = 'ccgate_amendb5';
mysql_select_db("$db") or die(mysql_error());
echo " <h1> YOU ARE Connected now !! </h1>";
echo " Quiz Results active <br> <br> ********************<br>  ";

$query = mysql_query("select testname, name FROM kcpe15questions");

$row = mysql_fetch_assoc($query);

if ($row['kcse-hist-f2-04-01-02-urbanization'] && $row['name']=='Amen')
{ 
  echo 'Subject Completed'; 
}
else
{ 
  echo '<br> urbanization f2-04-01-02';
}

mysql_close($dbcon);
?>

</head>
<body>
</body>
</html>

我认为你的问题是……

$row['kcse-hist-f2-04-01-02-urbanization']

我应该想象上面不是一个列名?$row获取数据库的列名

您最好先获取所有信息,将其存储在某个地方,然后创建if语句。

您没有在查询中选择列'kcse-hist-f2-04-01-02-urbanization',因此您的else语句一直在执行。

$query = mysql_query("select testname, name , kcse-hist-f2-04-01-02-urbanization FROM kcpe15questions");
$row= mysql_fetch_assoc($query);
if ($row['kcse-hist-f2-04-01-02-urbanization'] && $row['name']=='Amen')
{ 
 echo 'Subject Completed'; 
}