[英]My query won't work (it does in a wrong way) because of a script!? But why? SESSIONS and PHP
所以我必须为学校制作一个webapp。 U可以使用它来声明项目成本,名称,其他属性,登录名等,并且我在de下拉菜单中编写了一种按用户对项目进行排序的方法。
因此,在我的脚本中,它看起来是drowpdown菜单的值,然后将其放入查询中,这就是为什么我应该只用该用户的唯一代码来查看该特定用户的“项目” (将其从下拉值!) 。
我在Google Chrome控制台中使用jQuery查找了下拉菜单的值(jQuery行: $(“。li.li-primary-1 option:selected”)。val(); ) ,它为我提供了正确的值。
但是,每当我执行查询时,我总是得到错误的代码“ 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'] .'"';
并且也应该进行消毒,但是对于这个问题,这就是为什么您得到错误结果的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.