Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

46
Vistas
Two pieces of Code in same program HTML and PHP

I am very new to PHP and I have two different pieces of PHP code, as shown below. I do not know how to join these two together. Each time I try to join the two codes together, it only executes the top code. Any help I could get would be great!

Here are my two pieces of code I am trying to join up:

    <?php 
    if (isset($_POST["title"])) {
        require "db_conn.php";
        $title = $_POST["title"];


        if (empty($title)) {
            header("Location: index.php?mess=error#popup1");
        } else {
            $stmt = $conn->prepare("INSERT INTO todos(title) VALUE(?)");
            $res = $stmt->execute([$title]);

            if ($res) {
                header("Location: index.php?mess=success");
            } else {
                header("Location: index.php");
            }
            $conn = null;
            exit();
        }
    } else {
        header("Location: index.php?mess=error#popup1");
    }
    <?php 
    if (isset($_POST["description"])) {
        require "db_conn.php";
        $description = $_POST["description"];


        if (empty($description)) {
            header("Location: index.php?mess=error#popup1");
        } else {
            $stmt = $conn->prepare("INSERT INTO todos(description) VALUE(?)");
            $res = $stmt->execute([$description]);

            if ($res) {
                header("Location: index.php?mess=success");
            } else {
                header("Location: index.php");
            }
            $conn = null;
            exit();
        }
    } else {
        header("Location: index.php?mess=error#popup1");
    }
7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos