我正在构建一个应用程序。我尝试做的是当我用户登录为每个用户创建一个特定的页面时。我已经意识到这是第一页。因此,当用户登录时,下一页是包含其姓名和日历的页面。我现在要做的是,当用户点击日历的日期时,只从数据库中调用该用户的活动。我的问题是,在我输入用户个人资料后,当我点击日历的一个日期时,它不仅显示了该用户的活动,还显示了其他用户的活动...我该如何解决这个问题?请帮我... 以下是我的代码:
以下是用户登录的索引页面部分:
<form method="GET" action="signin.php" >
<table class="formtable">
<tr>
<td>
<input class="text" type="text" id="email_id" name="email" value="Adresa emailit" required="required" onfocus="changefocus(this,'Adresa emailit')" onblur="fillemptyform(this,'Adresa emailit')">
</td>
</tr>
<tr>
<td>
<input class="text" type="password" id="pass_id" name="pass" value="Password" required="required" onfocus="changefocus(this,'Password')" onblur="fillemptyform(this,'Password')">
</td>
</tr>
</table>
<input class="button" name="submit" type="submit" value="Sign in">
</form>
这是在用户登录时以sonn形式打开的sign in.php页面:(我只显示了使用php的部分)
<?php
//kontrollo per submitin e formes
if(isset($_GET['email']) AND isset($_GET['pass'])) {
$Emaili=$_GET['email'];
$Fjalekalimi=$_GET['pass'];
mysql_connect("127.0.0.1","root","") or die("Smund te lidhet me serverin");
mysql_select_db("axhenda") or die("Kjo databaze nuk u gjet");
$userquery = mysql_query("SELECT * FROM perdoruesi where Emaili = '$Emaili' AND Fjalekalimi = '$Fjalekalimi'") or die("Kjo query nuk mund te plotesohet");
if(mysql_num_rows($userquery) !=1) {
die ("Ky perdorues nuk u gjet");
}
while($row=mysql_fetch_array($userquery, MYSQL_ASSOC)) {
$Emri =$row['Emri'];
$Mbiemri =$row['Mbiemri'];
$Emaili =$row['Emaili'];
$Fjalekalimi =$row['Fjalekalimi'];
$Aksesi =$row['Aksesi'];
}
?>
<?php
} else die("Bosh");
?>
<div class="miresevini">
<span style="color: rgb(4, 38, 73); font-weight: bold;"> Welcome(</span>
<span style="color: #b2d7fd"><?php echo $Emri;?>, <?php echo $Mbiemri;?></span>
<span style="color: rgb(4, 38, 73);font-weight: bold;">)</span>
</div>
这是kalendar.php文件,当我点击一个日期时调用它,它显示该日期的所有活动
<body>
<?php
$con = mysql_connect('127.0.0.1','root','');
if (!$con) {
die('Lidhja me databazen nuk mund te kryhet' .mysql_error(). ' </body></html>');
}
if(!mysql_select_db("Axhenda",$con))
die('Nuk mund te hapet databaza Axhenda'.mysql_error(). '</body></html>');
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]'");
$count=mysql_num_rows($result);
?>
<div class="title"> Aktivitetet per daten <?php print ("$_POST[dataoutput]"); ?></div>
<form name="form1" method="post" action="delete.php">
<table >
<th>
<th ><strong>Emri </strong></th>
<th ><strong>Pershkrimi </strong></th>
<th><strong>Ora</strong></th>
</th>
<?php
while ($row=mysql_fetch_array($result)) {
?>
<tr>
<td ><input name="checkbox[]" type="checkbox" value="<?php echo $row['Id_Akt']; ?>"></td>
<td style="font-size:0.9em"><?php echo $row['Emri']; ?></td>
<td ><?php echo $row['Pershkrimi']; ?></td>
<td><?php echo $row['Ora']; ?></td>
</tr>
<?php
}
?>
</table>
<input class="button" name="delete" type="submit" value="Delete" style="margin-left:40%; margin-top:100px; width:15%">
</form>
</body>
请帮帮我。我应该怎么做才能只显示登录用户的活动... mysql中使用的表是两个:
Perdoruesi(Id_Per, Emri, Mbiemri, Emaili,Pass, Akses) saves information about the user
和
Aktiviteti(Id_Akt, Perd_Id, Emri, Pershkrimi, Date, Time), saves the information about the activity.
和Perd_Id是Perdoruesi表中Id_Per的外键。我还建立了外键和主键之间的关系,但我仍然没有得到特定用户的活动....请帮助我。提前谢谢!
我像这样修改了signin.php文件:(我添加了SESSION部分)
<?php
//kontrollo per submitin e formes
if(isset($_GET['email']) AND isset($_GET['pass']))
{$Emaili=$_GET['email'];
$Fjalekalimi=$_GET['pass'];
mysql_connect("127.0.0.1","root","") or die("Smund te lidhet me serverin");
mysql_select_db("axhenda") or die("Kjo databaze nuk u gjet");
$userquery = mysql_query("SELECT * FROM perdoruesi where Emaili = '$Emaili' AND Fjalekalimi = '$Fjalekalimi'") or die("Kjo query nuk mund te plotesohet");
if(mysql_num_rows($userquery) !=1)
{ die ("Ky perdorues nuk u gjet");
}
while($row=mysql_fetch_array($userquery, MYSQL_ASSOC))
{$Id_Per=$row['Id_Per'];
$Emri =$row['Emri'];
$Mbiemri =$row['Mbiemri'];
$Emaili =$row['Emaili'];
$Fjalekalimi =$row['Fjalekalimi'];
$Aksesi =$row['Aksesi'];
}
?>
<?php
}
else die("Bosh");
?>
<?php
session_start();
// store session data
$_SESSION['Id_Per'] = 1;
?>
并像这样修改了kalendar.php:
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]' and Perd_Id= $_SESSION['Id_Per']");
但它仍然给我这个错误:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\agenda\kalendar.php on line 63
我该怎么办?
答案 0 :(得分:0)
看起来像使用查询加载数据时
$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]'");
您正在选择该日期的所有数据。你需要像
这样的东西$result= mysql_query("SELECT * FROM Aktiviteti where Data= '$_POST[dataoutput]' and Email = '$_SESSION['email']'");
在上面的查询中,我假设您在会话中存储用户电子邮件。如果不是,您将需要能够访问它一些方法。这样,您只选择具有与之关联的当前用户电子邮件地址的记录。这也假设您正在存储每个用户的电子邮件地址以及当天的活动。
更新
登录示例
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['password']) && isset($_POST['username']) {
// Check to see if username and password is correct
// Should return user if correct else false
$user = authenticate($_POST['username'], $_POST['password']);
if($user){
$_SESSION['user'] = $user['username'];
$_SESSION['user_id'] = $user['id'];
$_SESSION['email'] = $user['email'];
} else {
// Handel user not being authenticated
} else {
// Handle the username and password not being present
}
}
?>
示例获取db。
的信息<?php
$q = "SELECT * FROM table_name WHERE Data = " . $_POST['item'] . " and user_id = " . $_SESSION['user_id'];
$result = mysql_query($q);
// Do something with the result.
?>