Save content from an HTML checkbox in MySql using PHP

0

I am new using PHP and HTML. I'm using Xampp, where I have a database of "test", with a table named "table" and with a single attribute of type boolean called "accepted". The problem I have is that when I try to execute the php code when making the HTML form, instead of executing the code, the browser opens the php file.

This is my .php:

<?php

    //Conectar con el servidor
    $conectar = mysql_connect('localhost', 'root', '') or die ("No se pudo conectar con el servidor");
    //Verificar la conexion

        $bd = mysql_select_db('prueba', $conectar) or die ("No se encontro la Base de Datos");

    //Recuperar variables
    $aceptado = "$_POST['aceptado']";
    $bool = isset($aceptado);
    //Hacer la sentencia
    $sql = "INSERT INTO tabla VALUES ('$bool')";
    //Ejecutar la sentencia".
    $ejecutar = mysql_query($sql, $conectar);

    if(!$ejecutar)
    {
        echo "ERROR al ejecutar";
    }
    else
    {
        echo "Datos guardados correctamente <br> <a href = 'single-colummn.html'>Volver </a>";
    }

?>

And this is the code part of the HTML form with which I want to run this:

<form action = "guardar.php" method = "POST">

        <p>Aceptado<input type="checkbox" name="aceptado" value="1" /></center></p>
    
asked by pepito 14.06.2018 в 17:20
source

0 answers