所以我必须为学校制作一个网络应用程序。您可以使用它来声明项目成本、名称、其他属性、登录等,并且我编写了一种在下拉菜单中按用户对项目进行排序的方法。
因此,在我的脚本中,它会查找下拉菜单的值并将其放入查询中,这就是为什么我应该只看到该特定用户的“项目”以及他/她的唯一代码(将其从下拉值中取出!)。
我在 Google Chrome 控制台中使用 jQuery 查找了下拉菜单的值( jQuery 行:$(".li.li-primary-1 option:selected").val() ; ) 它给了我正确的值(value)。
但是每当我执行查询时,我总是得到错误的代码“1007”。
我尝试了很多不同的方法,但没有成功。有人可以指出这篇文章完全错误的地方吗?需要一些解释。提前致谢! :)
<img src="assets/logo.png" width="150" style="margin-right: auto; position:static; display:block; margin-top: 0.5%;margin-left: 0.5%;">
<span class="echo-user"> <?php echo $_SESSION['name'];?>, <?php echo $_SESSION['consultantcode']; ?>
<br><div class="btn-group btn-group-lg">
<a href="uitloggen.php"><button type="submit" name="dangerbutton" class="btn btn-danger" id="btn-btn-danger-1">Uitloggen</button></a>
</div>
</span>
</div>
<div class="decla">
<h2>Declarations per project</h2>
<form id="content-project" name="search" method="post">
<div class="field">
<label>Choose project:</label>
<select name="peruser" class="li li-primary-1">
<?php
$query = "SELECT * FROM consultant";
$q = $db->prepare($query);
$q->execute();
$qry = $q->fetchAll(PDO::FETCH_ASSOC);
foreach ($qry as $qe) {
echo "<option value='" .$qe['consultantcode']. "'>".$qe['naam']."</option>";
}
?>
</select>
<br /><input class="btn btn-default" style="width: 20%; margin-left: 20.5%;" type="submit" name="submit" value="Zoeken" />
<a href="adminpage.php"><button class="btn btn-primary">Terug</btn></a>
</div>
</form>
</p>
<?php
if (isset($_POST['submit'])) {
?>
<p>
<center>
<table class='declaraties' style='border-collapse: collapse'>
<thead>
<tr>
<th><b>Declaratie code </b></th>
<th><b>Project code </b></th>
<th><b>Project naam </b></th>
<th><b>Omschrijving</b></th>
<th><b>Kosten code </b></th>
<th><b>Datum</b></th>
<th><b>Consultant code </b></th>
</tr>
</thead>
<tbody>
<?php
$cc = $_SESSION['consultantcode'];
$query = 'SELECT consultant.consultantcode, consultant.naam,
declaratie.declaratiecode, declaratie.kostencode, declaratie.datum,
project.projectnaam, project.projectcode, kosten.omschrijving,
kosten.kostencode, consultant.naam, consultant.consultantcode
FROM declaratie
INNER JOIN project
ON project.projectcode = declaratie.projectcode
INNER JOIN kosten
ON kosten.kostencode = declaratie.kostencode
INNER JOIN consultant
ON consultant.consultantcode = declaratie.consultantcode
WHERE declaratie.consultantcode ="'.$qe['consultantcode'] .'"';
$data = $db->prepare($query);
$data->execute(array());
$rows = $data->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row)
{
echo "<tr><td>"
. $row['declaratiecode'] . "</td><td>"
. $row['projectcode'] . "</td><td>"
. $row['projectnaam'] . "</td><td>"
. $row['omschrijving'] . "</td><td>"
. $row['kostencode'] . "</td><td>"
. $row['datum'] . "</td><td>"
. $row['consultantcode'] . "</td><td>"
. "</td></tr>";
}
// echo "<td style='margin-top:2%;'>" . $qewat. "<br>" . $qewa . "</td>";
}
?>
</tbody>
</table>
</center>
</p>
</div>
<div class="modal fade declaraties-modal-email" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Mijn declaraties</h4>
</div>
<div class="modal-body">
<p>
<center>
<table class='declaraties' style='border-collapse: collapse'>
<thead>
<tr>
<th><b>Declaratie code </b></th>
<th><b>Project naam </b></th>
<th><b>Project code </b></th>
<th><b>Kosten code </b></th>
<th><b>Datum</b></th>
</tr>
</thead>
<tbody>
<?php include_once 'mijndeclaratie.php';?>
</tbody>
</table>
</center>
</p>
</div>
<!-- <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div> -->
</div><!-- /.modal-content -->
<script type="text/javascript">
$('.btn.btn-danger.1').on("click", function() {
alert('U bent uitgelogd!');
});
</script>
最佳答案
您正在选择选项下拉循环中的最后一个结果。
WHERE declaratie.consultantcode ="'.$qe['consultantcode'] .'"';
应该是这样
WHERE declaratie.consultantcode ="'.$_POST['peruser'] .'"';
它也应该被清理,但是对于这个问题,这就是你得到错误结果的原因。
关于javascript - 由于脚本的原因,我的查询无法工作(它以错误的方式工作)!?但为什么? session 和 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26810103/