我有一件很簡單的事情要到這裏去。基本查詢,但當我決定更進一步時,我向自己投擲了一條曲線。如何檢查訂單是否已放入
基本上它是這樣的:
- 檢查,如果用戶在表單
- 如果沒有輸入值,任意球開出,並顯示一個基本的錯誤
- 如果他們再覈對該值該數據庫,以確保它是有效的/存在
- 如果它是有效的/存在,設置會話變量,走訂單
- 如果沒有,任意球開出,並顯示一個基本的錯誤
我想現在要做的是在那裏添加另一個檢查,如果用戶ID存在,那麼我需要檢查訂單狀態,如果他們已經訂購,那麼我想踢出並顯示一個簡單的消息讓他們知道他們已經下了訂單並正在處理。如果他們還沒有訂購,我想繼續按照上面的訂單。
數據庫有一個名爲「ordered」的字段,如果它們已經排序,那麼它有1;如果它們還沒有排序,則有0。
這裏是我的代碼工作,我已經試過幾件事情,但它一直吹起來:
<?php
session_start();
$db_host = 'localhost';
$db_username = 'xxxxxx';
$db_password = 'xxxxxxxx';
$db_name = 'xxxxxxxx';
mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name);
if ($_SERVER['REQUEST_METHOD'] == "POST") {
/** Check whether the user has filled in the text field "employee_id" */
if ($_POST['employee_id'] == "") {
$IdIsEmpty = true;
}else{
$employee_id = $_POST['employee_id'];
if(mysql_num_rows(mysql_query("SELECT employee_id FROM TABLE_2 WHERE employee_id = '$employee_id'"))){
// if userid exists
$_SESSION['emp_id'] = $employee_id;
header('Location: orderform.php');
exit;
}
$IdNotFound = true;
}
}?>
<head>
</head>
<body>
<b>Please enter your Employee ID: </b><br><br>
<form class="" action="index.php" method="post" enctype=
"multipart/form-data" name="test_form" id="test" accept-charset=
"utf-8"><input type="text" name="employee_id">
<?php
/** Display error messages if "employee_id" field is empty or if ID does not exist */
if ($IdIsEmpty) {
echo ("<br>");
echo ("<b>Enter your employee ID, please!</b>");
echo ("<br>");
}?>
<?php
/** Display error messages if "employee_id" field is empty or if ID does not exist */
if ($IdNotFound) {
echo ("<br>");
echo ("<b>Your employee ID not found!</b>");
echo ("<br>");
}?>
<input type="submit" value="Submit">
</form>
</body>
</html>
停止()'!改用MySQLi/PDO。而對於你的問題,你可以添加更多的查詢來檢查。你有什麼困難? – Raptor 2013-04-24 02:13:34