如何合并create.php,remove.php,edit.php

时间:2015-08-02 20:48:18

标签: php mysql phpmyadmin

我正在尝试编写管理面板,并使用3个不同的PHP文件:create.phpedit.phpremove.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');
?>

1 个答案:

答案 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文件。