2011-10-22 31 views
0
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>&nbsp".$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> 

好返回任何东西,现在,这个代码工作在我的电脑,我用它来开发这个我的网站上,这是它从数据库返回的行。但是,当我将这段代码放到我的网站上时,它不会返回任何内容,实际上,脚本甚至不显示任何内容。我会很感激,如果我可以得到任何帮助,它现在已经让我不眠之夜太久了...PHP while循环不在服务器上

+2

你有相同的数据和日相同的mysql相同的登录数据(主机,用户,密码)?你是否收到error_reporting的错误消息? – Anonymous

+0

哦,我的这段代码非常需要一些正确的格式和缩进。我强烈建议花一些时间学习和实现Drupal编码标准(http://drupal.org/coding-standards),或者简单地做一个Google搜索“php编码标准”,看看还有什么。你的灰色细胞(以及你寻求帮助的人)会感谢你。 :) –

+0

@BrianShowalter在易读性问题中重新分配代码......并立即发现了几个问题,同时这样做... – DaveRandom

回答

0

我推测从$_GET用法,你在浏览器中运行这个,而不是从一个控制台。这可能是因为你的mysql扩展没有加载,或者你没有与数据库服务器的有效连接。

  • 首先,检查你的错误日志。这些通常与您的Apache访问日志*保持在同一个地方。这会给你一个错误信息来处理。
  • 接下来,在您服务器上的空白页面中运行<?php phpinfo(); ?>,并查看您的基于Web的PHP是否支持MySQL支持。
  • 尝试运行mysql_error()后可能会失败的数据库操作。这也是挖掘错误的好方法。

最后要记住,你的脚本目前有SQL注入安全漏洞。修复这些probs之前,你去住这个:-)。

编辑:*您的服务器日志的位置取决于您正在使用的操作系统,并且您没有指定此位置。这很容易从搜索引擎中获得,但是 - 如果您在Windows上,那么请执行“Windows apache日志位置”的网页搜索。简单;-)

编辑2:如果SSH已被禁用,并且您觉得您需要它,请与您的主机通话。然而,这是一个单独的问题,你不需要它来解决手头的问题。如果你的phpMyAdmin有问题,请重新安装它,或使用你的主机提供的那个。 (如果您使用的是cPanel,则包含在您的控制面板中。)

+0

您需要使用反标符号让StackOverflow识别内联代码。 – Alex

+0

@halfer如果你必须解释你的代码不应该看起来像这样,你肯定有必要这样做...... – DaveRandom

+0

好吧,现在当我使用phpmyadmin的时候,它不停地给我下面的消息; import.php:缺少参数:import_type(FAQ 2.8) import.php:缺少参数:格式(FAQ 2.8)。加上我的SSh终端已被我的服务提供商禁用,就像我的httpd配置文件,任何帮助将不胜感激。 – invoq

1

我看不到任何直接的原因,为什么您的脚本不应该运行,因为halfer指出您的消息和错误日志是最好的地方看。

顺便说一句,虽然:在while循环的第一行if($row = Null)永远不会为真(如果它是,while循环将不进入) 考虑

$n_rows = 0; 
while($row = mysql_fetch_array($result)) { 
    $n_rows++; 
    // Process row 
} 
if(!$n_rows) { 
    // No rows message 
} 

(我知道这应该是评论不是一个答案,但我没有点)

+0

欢迎,并有一些要点:) – halfer

+0

感谢球员,@halfer,在我上面介绍的代码中的sql查询工作在我的PC的服务器/数据库和MySQL支持是由我的基于Web的PHP支持,因为另一个PHP文件输入数据到数据库中,但是,如果你能指示我可以检查我的错误日志和apache访问日志,我将不胜感激。另一个有趣的事情是,PHP代码之后的表格由于某种原因没有显示,我不明白这一点,但它可以在我的PC上运行,并且PHPmyadmin向我显示表格和其中的数据。 – invoq

1

试试这个(见注释代码更改):

<?php 

    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"]."'"; 
    } else { 
    // Pretty sure this should be in an else block 
    // As it was, the query above would never be executed, because it would 
    // always be overwritten by this one 
    $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"; 

    /* 
    Do you really not want the result of this query? 
    Shouldn't you be catching the results in a variable? 
    If not, consider adding a LIMIT 1 clause to the query, as the 
    database will have to do more work to return a full result set 
    you never use... 
    Regardless of that, testing for !mysql_query doesn't tell you there 
    were no results, it tells you whether the query itself failed. You 
    test the number of results using mysql_num_rows() or a SELECT count() query 
    */ 
    if (mysql_num_rows(mysql_query($ment, $con)) < 1) { 
    die('There are no posts matching your search, please enter another search in either another location or category, or both. '); 
    } 

    // Same goes for this. 
    // However, since you definitely do want the results of this, why run it twice? 
    $result = mysql_query($tester,$con); 
    if (mysql_num_rows($result) < 1) { 
    die('There are no posts matching your search, please enter another search in either another location or category, or both.'); 
    } 

    // Use mysql_fetch_assoc() instead of mysql_fetch_array(), it's more efficient 
    while ($row = mysql_fetch_assoc($result)) { 
    // if ($row == Null) { 
    // Sorry, what? If the row is null?? 
    // It will never be null... if it were, the loop would break immediately 
    // and never reach this point, plus mysql_fetch_* never returns 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>&nbsp".$row['mobile']."</b>"; 
    if ($row['image'] != Null) { 
     echo "<img src='upload/".$row['image']."' class='relt'/>"; 
    } 
    echo "</td></tr>"; 
    } 

?> 

<tr> 
    <td colspan='4'> 
    <!-- 
     Really? You can't just use a CSS height? 
    --> 
    <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> 
+0

彻底的答案,+1。虽然我会说这些属性应该使用双引号而不是单引号 - 尽管当然,用双引号字符串指定它们是一种痛苦......;) – halfer