PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] How to merge create.php, remove.php, edit.php

 February 01, 2022     mysql, php, phpmyadmin     No comments   

Issue

I am trying to write an admin panel and I use 3 different PHP files: create.php, edit.php and remove.php. Is there any way to merge all of them into one PHP file?

<?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');
?>

Solution

Here is a better idea. Make an index.php file which contains:

<?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.";

?>

So when you access the link for example: http://example.com/index.php?action=create this will include create.php file in the index.php etc..



Answered By - Sayed
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing