我正尝试使用PHP创建新页面(文件)。创建一个新的HTML页面并使用PHP添加内容
我已经打开并创建了页面,我已经从MySQL添加了它的内容,但是我无法从上一页获取id变量。
我的管理面板是这样的:
<?php
if(isset($_POST['sayfaekle'])) {
$baslik = $_POST['baslik'];
$text = $_POST['editor1'];
$sql = "INSERT INTO sayfa (sayfa_baslik , sayfa_text) VALUES ('$baslik' , '$text')";
$db->exec($sql);
$id=$db->lastInsertId();
echo "basarılı";
include "sayfagonder.php";
}
?>
在这里,我得到baslik和伢子并插入到数据库成功。我也成功地获得了ID。
在其他页面,创建一个新的PHP页面代码是这样的:
<?php
$_GET['id'] = $id;
ini_set('display_errors','0');
error_reporting(0);
$pagename = '../'.$baslik. '.php' ;
$myfile = fopen($pagename , "w");
$text = ' <?php
include "config.php";
$id = $_GET["id"];
echo $id;
$sayfasor=$db->prepare("select * from sayfa where sayfa_id=$id");
$sayfasor->execute(array(0));
$sayfacek=$sayfasor->fetch(PDO::FETCH_ASSOC);
include "header.php";
?>
<div class="content">
<div class="row">
<div class="pageana">
<div class="col-sm-8">
<h1><?php echo $sayfacek["sayfa_baslik"]; ?></h1>
<?php echo $sayfacek["sayfa_text"]; ?>
</div>
</div>
</div>
</div>
</div>
<?php
include "footer.php";
?> ';
fwrite($myfile , $text);
fclose($myfile);
?>
而且我得到这个错误:
Notice: Undefined index: id in C:\xampp\htdocs\doktor\deneme56.php on line 5
我不能得到id的值..
我假设你动态创建的页面。但是当你访问你创建的页面时,你需要有'url /?id = something'。这会让你在'$ _GET ['id']'里面有一个值。仅仅因为你已经在当前页面中设置了$ _GET ['id'] = something',并不意味着它会在下一个(甚至是在生成的页面中) – FirstOne
'$ text = '<?php等''???那将不起作用 – RamRaider
btw;太多的问题,没有人接受。 –