PHP while 循环没有在服务器上返回任何内容
if ($area == Null || $area == "Area of City") {
$ment = "CREATE OR REPLACE VIEW water
AS SELECT postable.postid, description, dated, image, posterid, country, state, city, area, cat
FROM postable
INNER JOIN ".$_GET['Cat']."
ON postable.postid = ".$_GET['Cat'].".postid
WHERE ".$_GET["Cat"].".cat = '".$_GET["what"]."'
AND postable.country = '".$_GET["Country"]."'
AND postable.state = '".$_GET["State"]."'
AND postable.city = '".$_GET["City"]."'";
}
$ment = "CREATE OR REPLACE VIEW water
AS SELECT postable.postid, description, dated, image, posterid, country, state, city, area, cat
FROM postable, ".$_GET["Cat"]."
WHERE (
(postable.postid = ".$_GET["Cat"].".postid
AND ".$_GET["Cat"].".cat = '".$_GET["what"]."'
AND postable.country = '".$_GET["Country"]."'
AND postable.state = '".$_GET["State"]."'
AND postable.city = '".$_GET["City"]."'
AND postable.area = '".$area."')
OR
(postable.postid = ".$_GET["Cat"].".postid
AND ".$_GET["Cat"].".cat = '".$_GET["what"]."'
AND postable.country = '".$_GET["Country"]."'
AND postable.state = '".$_GET["State"]."'
AND postable.city = '".$_GET["City"]."')
)";
$tester = "SELECT * FROM water, userguy
WHERE userguy.posterid = water.posterid";
if (!mysql_query($ment, $con)) {
die('There are no posts matching your search, please enter another search in either another location or category, or both. ' );
}
if (!mysql_query($tester,$con)) {
die('There are no posts matching your search, please enter another search in either another location or category, or both.');
}
$result = mysql_query($tester,$con);
while ($row = mysql_fetch_array($result)) {
if ($row == Null) {
echo "<tr><td colspan'4'>There are no posts matching your search, please enter another search in either another location or category, or both.</td></tr>";}
echo "<tr><td colspan='4' class='sult'>";
echo "<div id='main'>".$row['description']."</div> ".$row['dated']." <a href='mai.php?tofield=".$row['email']."'><b>".$row['email']."</b></a><b> ".$row['mobile']."</b>";
if ($row['image'] != Null) {
echo "<img src='upload/".$row['image']."' class='relt'/>";
}
echo "</td></tr>";
}
?>
<tr>
<td colspan='4'>
<br/><br/><br/><br/>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<img src='first.jpg'/>
</td>
<td colspan='2' align='center'>
<img src='second.jpg'/>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<img src='high.jpg'/>
</td>
<td colspan='2'></td>
</tr>
</table>
</body>
好的,现在,这段代码可以在我的计算机上运行,我用它来开发我的网站,即它从数据库返回行。但是,当我将此代码放在我的网站上时,它不会返回任何内容,事实上,脚本后面的表格甚至根本不显示。如果我能得到任何帮助,我将不胜感激,它已经让我失眠了太久了......
if ($area == Null || $area == "Area of City") {
$ment = "CREATE OR REPLACE VIEW water
AS SELECT postable.postid, description, dated, image, posterid, country, state, city, area, cat
FROM postable
INNER JOIN ".$_GET['Cat']."
ON postable.postid = ".$_GET['Cat'].".postid
WHERE ".$_GET["Cat"].".cat = '".$_GET["what"]."'
AND postable.country = '".$_GET["Country"]."'
AND postable.state = '".$_GET["State"]."'
AND postable.city = '".$_GET["City"]."'";
}
$ment = "CREATE OR REPLACE VIEW water
AS SELECT postable.postid, description, dated, image, posterid, country, state, city, area, cat
FROM postable, ".$_GET["Cat"]."
WHERE (
(postable.postid = ".$_GET["Cat"].".postid
AND ".$_GET["Cat"].".cat = '".$_GET["what"]."'
AND postable.country = '".$_GET["Country"]."'
AND postable.state = '".$_GET["State"]."'
AND postable.city = '".$_GET["City"]."'
AND postable.area = '".$area."')
OR
(postable.postid = ".$_GET["Cat"].".postid
AND ".$_GET["Cat"].".cat = '".$_GET["what"]."'
AND postable.country = '".$_GET["Country"]."'
AND postable.state = '".$_GET["State"]."'
AND postable.city = '".$_GET["City"]."')
)";
$tester = "SELECT * FROM water, userguy
WHERE userguy.posterid = water.posterid";
if (!mysql_query($ment, $con)) {
die('There are no posts matching your search, please enter another search in either another location or category, or both. ' );
}
if (!mysql_query($tester,$con)) {
die('There are no posts matching your search, please enter another search in either another location or category, or both.');
}
$result = mysql_query($tester,$con);
while ($row = mysql_fetch_array($result)) {
if ($row == Null) {
echo "<tr><td colspan'4'>There are no posts matching your search, please enter another search in either another location or category, or both.</td></tr>";}
echo "<tr><td colspan='4' class='sult'>";
echo "<div id='main'>".$row['description']."</div> ".$row['dated']." <a href='mai.php?tofield=".$row['email']."'><b>".$row['email']."</b></a><b> ".$row['mobile']."</b>";
if ($row['image'] != Null) {
echo "<img src='upload/".$row['image']."' class='relt'/>";
}
echo "</td></tr>";
}
?>
<tr>
<td colspan='4'>
<br/><br/><br/><br/>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<img src='first.jpg'/>
</td>
<td colspan='2' align='center'>
<img src='second.jpg'/>
</td>
</tr>
<tr>
<td colspan='2' align='center'>
<img src='high.jpg'/>
</td>
<td colspan='2'></td>
</tr>
</table>
</body>
Ok, now, this code works on my computer which I use to develop this my site, that is it returns the row from the database. However, when I put this code on my site it does not return anything, in fact, the table after the script does not even display at all. I would be grateful if I can get any help on this, it has been giving me sleepless nights for too long now...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看不出您的脚本不应该运行的任何直接原因,因为 halfer 指出您的消息和错误日志是最好的查看位置。
顺便说一句: while 循环中的第一行
if($row = Null)
永远不会为 true (如果是,则不会进入 while 循环)考虑一下
(我意识到这应该是评论而不是答案,但我没有要点)
I can't see any immediate reason why your script shouldn't run, as halfer pointed out your message and error logs are the best place to look.
As an aside though: The first line in the while loop
if($row = Null)
will never be true (if it were, the while loop wouldn't be entered)Consider
(I realise this should be a comment not an answer but I don't have the points)
试试这个(请参阅代码中的注释以了解更改):
Try this (see comments in code for changes):
我从
$_GET
用法推测您是在浏览器中运行它,而不是从控制台中运行。可能是您的 mysql 扩展未加载,或者您没有与数据库服务器的有效连接。在服务器上的空白页面中,查看基于 Web 的 PHP 是否支持 mysql 支持。
最后请记住,您的脚本目前存在 SQL 注入安全漏洞。在开始使用之前解决这些问题:-)。
编辑:*服务器日志的位置取决于您使用的操作系统,并且您没有指定这一点。然而,这很容易从搜索引擎获得 - 如果您使用的是 Windows,则可以在 Web 上搜索“windows apache 日志位置”。简单;-)
编辑 2:如果 SSH 已被禁用,并且您认为需要它,请与您的主机联系。然而,这是一个单独的问题,您不需要它来解决手头的问题。如果您的 phpMyAdmin 有问题,请重新安装它,或使用您的主机提供的版本。 (如果您使用的是 cPanel,则它包含在您的控制面板中。)
I presume from the
$_GET
usage that you're running this in a browser, rather than from a console. It might be that your mysql extension is not loaded, or you don't have a valid connection to the database server.<?php phpinfo(); ?>
in an otherwise empty page on your server, and see if mysql support is supported by your web-based PHP.Lastly bear in mind that your script has SQL injection security holes in it at present. Fix those probs before you go live with this :-).
Edit: * the location of your server logs depends on what OS you are using, and you have not specified this. This is quite easy to get from a search engine, however - if you are on Windows, then do a web search for "windows apache logs location". Easy ;-)
Edit 2: if SSH has been disabled, and you feel you need it, talk to your host. That is however a separate problem, and you don't need it to tackle the issue at hand. If your phpMyAdmin has problems, re-install it, or use the one provided by your host. (If you are using cPanel, this is included in your control panel.)