- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个登录页面,当用户成功登录时,它会被带到欢迎页面,然后他可以点击预订事件。当用户点击预订事件时,日历会显示所有可以预订的事件。当用户点击预订某个事件时,clientEvent 表应该使用从登录页面和 activityEventID 中获取的 clientID 进行更新。但我收到错误:无法添加或更新子行:外键约束失败(fitnessconnect
。clientevent
,CONSTRAINT clientevent_ibfk_1
FOREIGN KEY ( activityEventID
) 引用资料 activityevent
(activityEventID
))
如果我没有从登录页面或其他地方正确获取 clientID,我不确定我在哪里犯了错误。
我也不确定如何传递 activityEventID a href='CreateNewActivityBooking.php?activityEventID=activityEventID' 我用过这个,但我不确定它是否正确
为了创建两个表,我使用了这个
create table activityEvent
(
activityEventID integer auto_increment,
date date,
title varchar(30),
description varchar(50),
price integer,
location varchar(30),
startTime time,
endTime time,
activityTitle varchar(30),
noOfPlaces integer,
restricted varchar(30),
personalTrainer_CoachID integer,
primary key (activityEventID),
foreign key (personalTrainer_CoachID) references personalTrainer_Coach(personalTrainer_CoachID)
);
create table clientEvent
(
clientEventID integer auto_increment,
activityEventID integer,
clientID integer,
primary key (clientEventID),
foreign key (activityEventID) references activityEvent(activityEventID),
foreign key (clientID) references client(clientID)
);
这是 login.html
<HTML>
<BODY>
<FORM action='login.php' method = 'POST'>
<label>Enter your username</label>
<input name="username" type="text"/>
<br/>
<label>Enter your password</label>
<input name="password" type="password"/>
<br/>
<input type="submit"/>
</FORM>
</BODY>
</HTML>
登录.php
<?php
session_start();
$userName = $_POST['username'];
$passWord = $_POST['password'];
require('connection.php');
$dbpwd="";
$con=mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database);
$sql ="select clientID, password from client where userName = '$userName'";
$result = mysqli_query($con,$sql);
while($row = $result->fetch_assoc())
{
$dbpwd =$row['password'];
$clientID =$_SESSION['clientID'];
$_SESSION['clientID']='$clientID';
}
if($dbpwd == $passWord)
{
header("Location: welcome.html");
}
else
{
echo"Passwords do not match";
echo"</br>";
echo"Please Try Again";
}
?>
welcome.html 这只是一个开始,它没有太多的功能
<html>
<head>
<title> Welcome </title>
</head>
<body>
<h1>Welcome!</h1>
<button onClick="window.location='calendarTest2.php';" > Book Activity</button>
</body>
</html>
calenderTest2.php
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["month"]))
$_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"]))
$_REQUEST["year"] = date("Y");
?>
<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 )
{
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 )
{
$next_month = 1;
$next_year = $cYear + 1;
}
require("BookingsDB.php");
$myBookingsDB = new BookingsDB();
$bookings = $myBookingsDB->getMonthlyBookings($cMonth,$cYear);
?>
<div align="left">
<table width="400" border="5" align="left" id="calendar">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF"><table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"]
. "?month=". $prev_month . "&year=" . $prev_year; ?>"
style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"]
. "?month=". $next_month . "&year=" . $next_year; ?>"
style="color:#FFFFFF">Next</a></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"><table width="100%" border="2" cellpadding="2"
cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong> <?php
echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">
<strong>S</strong></td>
</tr>
<?php
require("connection.php");
$con=mysqli_connect("$mysql_host","$mysql_user","$mysql_password","$mysql_database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = getdate();
for ($i=0; $i<($maxday+$startday); $i++)
{
if(($i % 7) == 0 )
{
echo "<tr> ";
}
if($i < $startday)
{
echo "<td></td> ";
}
else
{
$day = $i - $startday + 1;
$thisDate = new DateTime("$cYear-$cMonth-$day");
$jsEvent[] = "document.getElementById('trigger" . $i . "').onclick = function() {showForm()};";
echo "<td align='center' valign='middle' height='20px'><a href='CreateNewActivityBooking.php?activityEventID=activityEventID' id='trigger" . $i . "'>". ($i - $startday + 1) . "</a>";
foreach ($bookings as $key => $value)
{
if ($thisDate->format('Y-m-d') == $value['date']->format('Y-m-d'))
{
echo " ";
echo $value['title'];
echo " ";
echo $value['startTime'];
}
}
echo "</td>";
}
if(($i % 7) == 6 )
{
echo "</tr> ";
}
}
mysqli_close($con);
?>
<script type="text/javascript">
<?php foreach($jsEvent as $event)
{
echo $event;
}
?>
function showForm()
{
document.getElementById('timeslots').style.display="block";
};
</script>
</table></td>
</tr>
</table>
预订数据库.php
<?php
session_start();
class BookingsDB
{
private $bookings = array();
private $con;
public function BookingsDB()
{
require("connection.php");
$this->con = mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database);
}
public function getMonthlyBookings($thisMonth,$thisYear)
{
$sql = "SELECT activityEventID,date,title,startTime FROM activityEvent WHERE YEAR(date) = $thisYear AND MONTH(date) = $thisMonth";
$result = mysqli_query($this->con,$sql);
while($row=mysqli_fetch_array($result))
{
$this->bookings[] = array('date'=>new DateTime($row['date']), 'title'=>$row['title'],'startTime'=>$row['startTime']);
//$activityEventID =$_SESSION['activityEventID'];
//$_SESSION['activityEventID']='activityEventID';
}
return $this->bookings;
}
public function close()
{
mysqli_close($this->con);
}
}
?>
CreateNewActivityBooking.php
<?php
session_start();
require("connection.php");
$con=mysqli_connect("$mysql_host","$mysql_user","$mysql_password","$mysql_database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$clientID=$_SESSION['clientID'];
$activityEventID =$_SESSION['activityEventID'];
$sql="Insert into clientEvent(clientID, activityEventID) Values('$clientID','$activityEventID')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
?>
最佳答案
从您的代码来看,您似乎没有将 activityEventID
存储在 session 变量中。您正在尝试在 CreateNewActivityBooking.php 页面上访问它,同时将事件插入到“clientEvent”表中。
查看代码中的以下几行:
$clientID=$_SESSION['clientID'];
$activityEventID =$_SESSION['activityEventID']; //Here $_SESSION['activityEventID'] doesn't exists
因为“clientEvent”表对“activityEventID”列有外键约束。由于此约束将失败,查询将不会执行,您会收到错误。
所以基本上你需要找到一种方法来在那里传递正确的值。
编辑:至于您的评论,您发布的脚本似乎没有在 session 中存储“activityEventID”,因为您引用的行实际上是对您发布的相关脚本的评论。
这里要具体一点就是你需要做的。
在 BookingsDB.php 上
$this->bookings[] = array('date'=>new DateTime($row['date']), 'title'=>$row['title'],'startTime'=>$row['startTime'], 'activityEventID'=>$row['activityEventID']);
在你的 calenderTest2.php 上
echo "<td align='center' valign='middle' height='20px'>";
foreach ($bookings as $key => $value)
{
if ($thisDate->format('Y-m-d') == $value['date']->format('Y-m-d'))
{
echo "<a href='CreateNewActivityBooking.php?activityEventID=".$value['activityEventId']."' id='trigger" . $i . "'>". ($i - $startday + 1) . "</a>";
echo " ";
echo $value['title'];
echo " ";
echo $value['startTime'];
}
}
echo '</td>';
现在您正在为每个链接在查询字符串中传递 activityEventID。您可以在 CreateNewActivityBooking.php 中检索它,如下所示:
$activityEventID =$_GET['activityEventID'];
您可能需要在布局方面重新格式化一些东西,但我认为应该这样做。
关于PHP使用 session 从数据库中获取clientID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28749271/
我在核心 3.1 中使用谷歌身份验证。以前,我的代码运行良好,但在使用系统格式后,项目出现异常。*ArgumentException:必须提供“ClientId”选项。 (参数'ClientId')M
这是 .aspx 文件中的代码 Login Again function Validate() { if (document.getEle
我希望能够让各个用户使用 SignalR 相互发送消息,因此我需要发送到特定的客户端 ID。如何在 session 开始时为特定用户定义客户端 ID - 例如用户的 GUID 主键? 最佳答案 将 I
我正在尝试获取数据表中组件的客户端 ID。问题是 jsf 自动将行索引放在组件 id 之前,即 Update 对于第二行中的链接(索引 = 1)。 我正在使用以下方法来获取 clientId
我在页面上有 7 个 7 周的复选框和 7 天的单独时间选择器。选中复选框后,我想显示该工作日的时间选择器,如果未选中,我想隐藏相应的时间选择器 我已经使用以下代码来获取它,它也能正常工作。 func
我得到了一个我绑定(bind)到转发器的用户控件列表。 用户控件:(示例)“AppProduct” 转发器:
我在 Repeater 的 ItemTemplate 中有一个 TextBox,它也在 ItemTemplate 中。 服务器端我有: protected void txtValorMaterialA
由于指定clienID只是类MqttAndroidClient中的一个特性,在使用类IMqttClient和时不能指定IMqttAsynchClient. 连接具有唯一ID 的客户端的真正目的是什么?
我们在 Google Analytics 中定义了三个自定义维度: ClientId (dimension1): session 范围 SessionId (dimension2): session
我有一个中继器,里面有一些控件,其中一个是文本框。我正在尝试使用 jquery 获取文本框,我的代码如下所示: $("#").click(function (event) {}); 但我总是得到 nu
我有一个应用程序将由两个不同的实体使用,每个实体都有自己的 Azure Active Directory。 最初,我使用的代码是: var msalConfig = { auth: {
有谁知道在 Azure 中哪里可以找到我的 Azure Active Directory Graph 客户端 ID?我已经在 Azure 内部到处搜索过,但仍然没有运气。或者是否有人知道 powers
我在 .ascx 用户控件中遇到 扩展问题。 我有一个 .js 文件,其中包含 JavaScript 函数: function doSomething(objectId) { ... } 我
我正在尝试 Spring OAuth2 库的非常基本的实现;但是,当我向服务器发送请求时,我收到以下错误: { "error": "invalid_client", "error_descriptio
我有几个应该处理单个 bean 产生的不同类型错误的元素。现在,我从浏览器获取的某个元素的 clientID 始终相同,因为内部没有生成的 id(总共 3 个 ID)。 无论我将哪个 clientID
我有一个组合组件,它捆绑了一些输入字段。该组件将在页面上多次使用,并包含一个按钮,用于复制其中另一个组件的值。为此,我需要通过其 clientId 访问其中一个 sibling 作为 的目标 我的问
我试图在文档中找到它,但我没有在任何地方看到它。 在 CometD 中,clientId 的生命周期是多久? 因此,客户端登录并成功握手。现在他们有一个与服务器上的 session 关联的 clien
我可以获得所有 jms 主题订阅者的 ClientID 吗?我使用 Jboss AS 6 (HornetQ)。 当然,我可以向他们所有人发送查询并阅读回复,但我正在寻找更优雅的解决方案。 最佳答案 通
我想在动态生成的控件中设置所需的 ClientID。如果您有任何想法将所需的 ClientID 设置为控件而不是告诉我,则 ClientID 是只读的 最佳答案 这只能在 .Net 4 及更高版本中完
我在网格控件中有一个文本框控件。我想使用带有“”之类的 javascript 获取 textBox 的 clientID。但是我收到一条错误消息,指出当前上下文中不存在 txtBox。文本框以编程方式
我是一名优秀的程序员,十分优秀!