我想寫的如果任何變量是x(因爲在他們沒有設置),然後返回一條消息,「你錯過了一個問題」。任何人都可以幫助我的語法?
我已經嘗試設置變量$r
有我需要的,然後在下面的$Q18
行配售消息 - if $Q1 == "x"
然後echo $r
但這並沒有工作。
任何人都可以提供有用的幫助嗎?整個代碼如下...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="Locus.css" rel="stylesheet" type="text/css" /> <!-- LINKED ATTACHED STYLE SHEET-->
<title>Locus Test Complete</title>
</head>
<body>
<H4>Thank you for completing this test, please choose another from the menu.</H4>
<?php
/*DECLARING THE VARIABLES FOR ACCESS*/
$username="root";
$password="";
$database_server="localhost";
/*CONNECTING TO THE SERVER*/
$database="locus";
mysql_connect($database_server,$username,$password) or die("cannot connect");
/*CONNECTING TO THE DATABASE*/
mysql_select_db($database) or die("Unable to select database");
/*CHECK THE STATUS AND DECLARE THE VARIABLES*/
if(isset($_POST['surname'])) {
$Surname = $_POST['surname'];
} else {
$Surname = "";
}
if(isset($_POST['prison'])) {
$Prison = $_POST['prison'];
} else {
$Prison = "";
}
/*SHORTHAND WAY TO CHECK THE STATUS AND DECLARE THE VARIABLES*/
$NI = isset($_POST['NI']) ? $_POST['NI'] : "x";
$Q1 = isset($_POST['Q1']) ? $_POST['Q1'] : "x";
$Q2 = isset($_POST['Q2']) ? $_POST['Q2'] : "x";
$Q3 = isset($_POST['Q3']) ? $_POST['Q3'] : "x";
$Q4 = isset($_POST['Q4']) ? $_POST['Q4'] : "x";
$Q5 = isset($_POST['Q5']) ? $_POST['Q5'] : "x";
$Q6 = isset($_POST['Q6']) ? $_POST['Q6'] : "x";
$Q7 = isset($_POST['Q7']) ? $_POST['Q7'] : "x";
$Q8 = isset($_POST['Q8']) ? $_POST['Q8'] : "x";
$Q9 = isset($_POST['Q9']) ? $_POST['Q9'] : "x";
$Q10 = isset($_POST['Q10']) ? $_POST['Q10'] : "x";
$Q11 = isset($_POST['Q11']) ? $_POST['Q11'] : "x";
$Q12 = isset($_POST['Q12']) ? $_POST['Q12'] : "x";
$Q13 = isset($_POST['Q13']) ? $_POST['Q13'] : "x";
$Q14 = isset($_POST['Q14']) ? $_POST['Q14'] : "x";
$Q15 = isset($_POST['Q15']) ? $_POST['Q15'] : "x";
$Q16 = isset($_POST['Q16']) ? $_POST['Q16'] : "x";
$Q17 = isset($_POST['Q17']) ? $_POST['Q17'] : "x";
$Q18 = isset($_POST['Q18']) ? $_POST['Q18'] : "x";
/*PLACE THE VALUES OF THE VARIABLES WITHIN THE DATABASE TABLE*/
$query = "INSERT INTO locusofcontrolscores
VALUES(Null,'$Surname','$Prison','$NI','$Q1','$Q2','$Q3','$Q4','$Q5','$Q6','$Q7','$Q8','$Q9','$Q10','$Q11','$Q12','$Q13','$Q14','$Q15','$Q16','$Q17','$Q18')";
/*CREATE A QUERY FROM THE VARIABLE*/
mysql_query($query) or die(mysql_error());
/*CLOSE THE SERVER CONNECTION*/
mysql_close();
?>
</body>
</html>
你已經錯過了問題 – zerkms
@zerkms我們發現他錯過了! –
問題在頂部。 –