Error with $ _SERVER ['$ PHP_SELF']

0

I have a CRUD but when I insert it, I get the following error:

  

"Forbidden access!   You do not have permission to access the requested object. The object is protected against reading or the server can not read it.   If you believe that this is a server error, please communicate it to the portal administrator.   Error 403   localhost   Apache / 2.4.17 (Win32) OpenSSL / 1.0.2d PHP / 5.6.15 "

What I want is that each insertion takes me to the same page but with the record inserted the code is as follows:

<?php
$sql_local = "SELECT * FROM DATOS_USUARIOS";
$resultado = $base->prepare($sql_local);
$resultado->execute(array());

//--------- insertar datos----------

#si has pulsado el boton insertar
if(isset($_POST["agregar"])) {

    //almaceno las variables del formulario
    $nombre    = $_POST["Nom"];
    $apellido  = $_POST["Ape"];
    $direccion = $_POST["Dir"];

    $sql = "INSERT INTO DATOS_USUARIOS (NOMBRE, APELLIDO, DIRECCION) VALUES(:nom, :ape, :dir)";

    $resultado = $base->prepare($sql);

    $resultado->execute(array(
        ":nom" => $nombre,
        ":ape" => $apellido,
        ":dir" => $direccion
    ));

    header("Location:index.php");
}
?>

<h1>CRUD<span class="subtitulo">Create Read Update Delete</span></h1>

<form action="<?php echo $_SERVER['$PHP_SELF']; ?>" method="post">
    <table width="50%" border="0" align="center">
        <tr>
            <td class="primera_fila">Id</td>
            <td class="primera_fila">Nombre</td>
            <td class="primera_fila">Apellido</td>
            <td class="primera_fila">Dirección</td>
            <td class="sin">&nbsp;</td>
        </tr>
        <?php
        #por aca objeto persona que hay en el array registros repiteme el codigo que esta en el foreach
        foreach($registros as $persona): ?>
        <tr>
            <td><?php echo $persona->Id ?> </td>
            <td><?php echo $persona->Nombre ?></td>
            <td><?php echo $persona->Apellido ?></td>
            <td><?php echo $persona->Direccion ?></td>

        <?php endforeach; //cierro boloque foreach ?>

        <tr>
            <td></td>
            <td><input type='text' name='Nom' size='10' class='centrado'></td>
            <td><input type='text' name='Ape' size='10' class='centrado'></td>
            <td><input type='text' name=' Dir' size='10' class='centrado'></td>
            <td class='bot'><input type='submit' name='agregar' id='agregar' value='Insertar'></td>
        </tr>
<!-- /.. -->

I am working with phpMyAdmin with MySQL.

    
asked by Juanzu 06.08.2016 в 19:09
source

2 answers

1

Your error is here

$_SERVER['$PHP_SELF']

PHP_SELF is not a variable, it is a value within the SERVER array, try putting this

$_SERVER['PHP_SELF']
    
answered by 06.08.2016 / 23:25
source
1

The error is usually a symptom of Virtual Host policy settings or access permissions.

In this case, as a result of the comment, it has turned out to be an error in the configuration of action in the form.

<form action="<?php echo $_SERVER['$PHP_SELF']; ?>" method="post">

The variable $_SERVER['$PHP_SELF'] must be defined without the symbol $ in key .

$_SERVER['PHP_SELF']
    
answered by 06.08.2016 в 19:58