我正在尝试编写管理面板,并使用3个不同的PHP文件:create.php
,edit.php
和remove.php
。
有没有办法将所有这些合并到一个PHP文件中?
<?php
include 'connection.php';
$id = $_POST['id'];
$soru = $_POST['soru'];
$cevap = $_POST['cevap'];
if (!$_POST['submit'] ) {
echo "Please fill out the form";
} else {
mysql_query("INSERT INTO sss (soru,cevap,ID) VALUES ('$soru','$cevap','$id') ") or die(mysql_error());
header('Location:admin.php');
}
?>
<?php
include 'connection.php';
$id = $_POST['id'];
$soru = $_POST['soru'];
$cevap = $_POST['cevap'];
if (!$_POST['submitSoru'] ) {
echo "Please fill out the form";
} else {
mysql_query("UPDATE sss SET soru = '$soru' , cevap = '$cevap' WHERE ID = '$id' ") or die(mysql_error());
header('Location:admin.php');
?>
答案 0 :(得分:4)
这是一个更好的主意。制作包含以下内容的index.php
文件:
<?php
$action = $_GET['action'];
if ($action == 'create') {
include('create.php');
} elseif ($action == 'remove') {
include('remove.php');
} elseif ($action == 'edit') {
include('edit.php');
} else
echo "This page does not exist.";
?>
因此,当您访问链接时,例如:http://example.com/index.php?action=create
,这将在create.php
等中包含index.php
文件。