Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示数据库查询的最终结果时出错_Php_Mysql - Fatal编程技术网

Php 显示数据库查询的最终结果时出错

Php 显示数据库查询的最终结果时出错,php,mysql,Php,Mysql,请帮忙解决这个小问题,给一个大错误。我查询一个数据库,以输出多个单词的内容限制。成功了。但我发现很难在另一页上显示全部内容。 下面是有效的数据库查询 <?php require_once ('inc/mysqli_connect.php');// Connect to the db. $q = "select id,SUBSTRING_INDEX(description,' ',250) AS responsibity, SUBSTRING_INDEX(qualifica

请帮忙解决这个小问题,给一个大错误。我查询一个数据库,以输出多个单词的内容限制。成功了。但我发现很难在另一页上显示全部内容。 下面是有效的数据库查询

<?php 
    require_once ('inc/mysqli_connect.php');// Connect to the db.
    $q = "select id,SUBSTRING_INDEX(description,' ',250) AS responsibity, SUBSTRING_INDEX(qualification,' ',250) AS qualification,(post) AS position FROM career ORDER BY id DESC LIMIT 15";
    $r = @mysqli_query ($dbc, $q); // Run the query.

    if ($r) { // If it ran OK, display the records.
        echo '<h2>Open Positions</h2>';

    // Fetch and print all the records:
              while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
              echo'<ul>';
              echo '<li><a href="http://localhost/sitename/career-details.php?id
='.htmlentities($row['id']).'">'.htmlentities($row['position']).'</a>.</li>';
              echo '</ul>';
        }
        mysqli_free_result ($r); // Free up the resources.  

    } else { // If it did not run OK.

        // Public message:
        echo '<p class="error">The are no latest job openings please. We apologize for any inconvenience.</p>';

        // Debugging message:
        echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';

    } // End of if ($r) IF.
     ?>

很抱歉,我不知道如何格式化这个页面上的编码,因为我尝试了所有我不能使它混乱。请按顺序告诉我。

在代码中添加一些验证

$id = null;
if(isset($_GET['id'])){
   $id= intval($_GET['id']);
}
$q = "SELECT * FROM career WHERE id= '$id' ";
$r = @mysqli_query ($dbc, $q); // Run the query.
$rowcount = mysqli_num_rows($r);
if($rowcount > 0){
   // Fetch and print all the records:
}
还有一些类型错误,如

echo '<br>'.$row[' responsibility']; // '<br>$row['responsibility']
echo '<a href="apply.php>Apply.</a>'; // <a href="apply.php">Apply.</a>
echo'
。$row['responsibility'];/'
$row['responsibility'] 回显“”;//
在第一次查询中使用列别名:

SUBSTRING_INDEX(description,' ',250) AS responsibity
(post) AS position

您可以在第二个查询中使用
选择*
。您只能使用其中的原始列名,而不是
$row['responsibility']
$row['position']

很难计算行数,因此请指定错误行…您在这里有一个输入错误:
$row['responsibility']
。删除空格。首先检查(isset($\u GET['id']){$id=$\u GET['id'];//more code}@user1844933)是否在文章末尾指定了错误。正如第74行所示,您还应该将输入转义到sql字符串中,否则您可能会遭受sql注入攻击。例如,$id=mysql\u real\u escape\u string($\u GET['id'))会使您的id值免受sql注入攻击。它会给出以下错误:在第74行的脚本“C:\wamp\www\sitename\career details.php”中发生错误:未定义的索引:id@Martian,另一个错误是:脚本“C:\wamp\www\sitename\career details.php”第81行出现错误:使用未定义的常量行数-假定为“行数”@Roland Jansen,我按照您的要求执行了操作,但不知道为什么它仍然不起作用,请帮助
echo '<br>'.$row[' responsibility']; // '<br>$row['responsibility']
echo '<a href="apply.php>Apply.</a>'; // <a href="apply.php">Apply.</a>
SUBSTRING_INDEX(description,' ',250) AS responsibity
(post) AS position