PHP预订系统数据库

时间:2014-04-10 13:09:49

标签: php mysql sql database

我对php和数据库相当新,我使用xampp创建了一个预订系统。我有一个登录页面供用户预订,限制访问页面供管理员查看已经完成的所有预订。但是我似乎无法查看每个人所做的所有预订,只有用户做出的预订。我确定它与会话有关,但不确定哪个部分。帮助将不胜感激。

以下记录集代码仅显示已登录的用户,而不是所有预订的数据库。

谢谢

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) :     mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;    
case "long":
case "int":
  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  break;
case "double":
  $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  break;
case "date":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
case "defined":
  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  break;
 }
 return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Userid'])) {
$colname_Recordset1 = $_SESSION['MM_Userid'];
}
mysql_select_db($database_myconnectiono, $myconnectiono);
$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s",     GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $myconnectiono) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


?>

2 个答案:

答案 0 :(得分:2)

您的查询仅限一位用户使用。

$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int"));

在哪里说WHERE user_id = %s会将结果限制为只有该用户的结果。删除它,您将获得所有预订。

$query_Recordset1 = "SELECT * FROM booking";

您可能希望通过按用户,日期等排序结果来改进该查询。

答案 1 :(得分:0)

更改此行:

$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int"));

要:

$query_Recordset1 = sprintf("SELECT * FROM booking", GetSQLValueString($colname_Recordset1, "int"));

删除WHERE user_id = %s将返回预订表中的所有行。