PHP在新页面上显示SQL行的更多列,然后保存它

PHP在新页面上显示SQL行的更多列,然后保存它,php,mysql,get,file-get-contents,str-replace,Php,Mysql,Get,File Get Contents,Str Replace,这里的任何帮助都是难以置信的: 所需的工作流:用户浏览sql行(第1页),仅显示选择性数据。单击一行后,它将(第2页的脚本)路由到显示该行所有数据的页面(第3页)。该页面保存在目录中 第1页(index.php) 你的问题似乎就在这里 $query="SELECT * FROM `stories` WHERE id=$_GET[id]"; $\u GET[id]为空,变量为$\u GET['id'] 只是,在第2页测试这段代码 if(isset($_GET['id'])){ if(is_nu

这里的任何帮助都是难以置信的:
所需的工作流:用户浏览sql行(第1页),仅显示选择性数据。单击一行后,它将(第2页的脚本)路由到显示该行所有数据的页面(第3页)。该页面保存在目录中

第1页(index.php)


你的问题似乎就在这里

$query="SELECT * FROM `stories` WHERE id=$_GET[id]";
$\u GET[id]
为空,变量为
$\u GET['id']

只是,在第2页测试这段代码

if(isset($_GET['id'])){
 if(is_numeric($_GET['id'])) {  //check if $_GET['id'] is a number
  $id=$_GET['id'];


  include("db.php");
  $query="SELECT * FROM `stories` WHERE id=$id";
echo $query;  //show the query.
  $result=mysqli_query($connection,$query);
  while ($data = mysqli_fetch_assoc($result)):
    $id = $data['id'];
    $author = $data['author'];
    $title = $data['title'];
    $page_path = $data['page_path'];
echo "id=".$id." author=".$author." title=".$title." page_path=".$page_path;
//show your variables.
    if(is_null($page_path)){$page_path = "#";}

if(is_file($page_path)){
        $data2 = file_get_contents("single-page.php");
        $data2 = str_replace($title2, $title, $data2);
        $data2 = str_replace($author2, $author, $data2);

        file_put_contents($page_path, $data2);
     }
else
echo "file".$page_path." doesnt exist :(";
  endwhile;
  mysqli_close($connection);
  }else echo "ID is not numeric";
 }else echo "error on ID data";

尝试打印诸如mysqli_query('---')或die('query not executed')之类的错误。在第二页中,GET[id]-->change to GET['id']我在dreamweaver中将[id]更改为['id']时出现语法错误。我在dreamweaver中遇到语法错误。第4行-定义id时,不喜欢使用“id”。脚本未运行,您添加的错误也未报告。好主意,尽管我需要改变我对包含它们的想法,但是错误仍然在回响。还有什么建议吗?非常感谢您的时间。@buzrw现在检查,我添加的是数字条件。它们已经都是数字了。我做了一些建议性的更改,我还了解到文件路径需要是服务器本地的,而不是http,因为我使用的是Linux。仍然不起作用,我调整了代码,将标签放在页面的括号中。我将上面的代码编辑为我当前使用的代码。另外,当我运行这段代码并查看它冻结运行的页面的源代码时,我得到了以下结果:下面是一个$page_路径值single pages/1-trebort-ouzzub-coatomer-proteinomplexubunit-gamma.phpok的示例,让我们集中在第2页。。。当您在浏览器中放入localhost/path\u to\u file/create\u page.php时会发生什么?id=1。。。它显示了什么吗?
<!DOCTYPE HTML>
<html>
    <head>
        <title>
            <?php echo $title2; ?>
        </title>
    </head>
    <body>
        <?php echo $title2; ?>
        <?php echo $author2; ?>
    </body>
</html>
<?php
// Start the buffering //
ob_start();
?>
Your page content bla bla bla bla ...

<?php
 echo '1';

 // Get the content that is in the buffer and put it             
In your file //
file_put_contents('yourpage.html',  
ob_get_contents());
 ?>
$query="SELECT * FROM `stories` WHERE id=$_GET[id]";
if(isset($_GET['id'])){
 if(is_numeric($_GET['id'])) {  //check if $_GET['id'] is a number
  $id=$_GET['id'];


  include("db.php");
  $query="SELECT * FROM `stories` WHERE id=$id";
echo $query;  //show the query.
  $result=mysqli_query($connection,$query);
  while ($data = mysqli_fetch_assoc($result)):
    $id = $data['id'];
    $author = $data['author'];
    $title = $data['title'];
    $page_path = $data['page_path'];
echo "id=".$id." author=".$author." title=".$title." page_path=".$page_path;
//show your variables.
    if(is_null($page_path)){$page_path = "#";}

if(is_file($page_path)){
        $data2 = file_get_contents("single-page.php");
        $data2 = str_replace($title2, $title, $data2);
        $data2 = str_replace($author2, $author, $data2);

        file_put_contents($page_path, $data2);
     }
else
echo "file".$page_path." doesnt exist :(";
  endwhile;
  mysqli_close($connection);
  }else echo "ID is not numeric";
 }else echo "error on ID data";