作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
New Approved -6ren">
这是我的代码:
<p>Select application status to view.</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="type" style="width:100px;">
<option name="New">New</option>
<option name="Approved">Approved</option>
<option name="Denied">Denied</option>
<option name="In Training">In Training</option>
<option name="Passed">Passed</option>
<option name="Retrained">Retrained</option>
<option name="Failed">Failed</option>
<option name="Placed">Placed</option>
</select>
<input type="submit" value="Go" />
</form>
<?php if (!isset($_POST['type'])):
$newapps = mysql_query('SELECT aid, status, Day, Dte, Month, Year, email, Character_Name FROM applications WHERE status LIKE "New"'); ?>
<table>
<tr>
<td><strong>ID</strong></td>
<td><strong>Status</strong></td>
<td><strong>Date Submitted</strong></td>
<td><strong>E-mail</strong></td>
<td><strong>Character Name</strong></td>
</tr>
<?php while ($newapp = mysql_fetch_array($newapps))
{
$aid = $newapp['aid'];
$status = $newapp['status'];
$day = $newapp['Day'];
$date = $newapp['Dte'];
$month = $newapp['Month'];
$year = $newapp['Year'];
$email = $newapp['email'];
$name = $newapp['Character_Name'];
echo "<tr><td>$aid</td><td>$status</td><td>$day, $month $date $year</td><td>$email</td><td>$name</td></tr>\n";
}
?>
</table>
<?php else:
$query1 = "SELECT aid, status, Day, Dte, Month, Year, email, Character_Name FROM applications WHERE status LIKE '{$_POST['type']}'";
$result = mysql_query('$query1') or die(mysql_error());
?>
<table>
<tr>
<td><strong>ID</strong></td>
<td><strong>Status</strong></td>
<td><strong>Date Submitted</strong></td>
<td><strong>E-mail</strong></td>
<td><strong>Character Name</strong></td>
</tr>
<?php while ($applist = mysql_fetch_array($result))
{
$aid = $applist['aid'];
$status = $applist['status'];
$day = $applist['Day'];
$date = $applist['Dte'];
$month = $applist['Month'];
$year = $applist['Year'];
$email = $applist['email'];
$name = $applist['Character_Name'];
echo "<tr><td>$aid</td><td>$status</td><td>$day, $month $date $year</td><td>$email</td><td>$name</td></tr>\n";
}
?>
</table>
<?php endif; ?>
当我加载页面时,它会正确地拉取"new"应用程序。但是当我运行一个查询来提取,例如,Approved apps,我得到这个错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query1' at line 1
知道我遗漏了什么吗?
最佳答案
您将 $query
括在单引号中,导致按字面意思理解。
使用双引号,或者根本不使用:
mysql_query($query1)
关于php - 带有 WHERE 子句失败的简单 mysql_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4904289/
我是一名优秀的程序员,十分优秀!