Skip to content
Advertisement

Lost data because of 301 error (POST)

I’ve a 301 error after doing my POST Form… When I submit my form, I lose all my data and I don’t know why. I search on the net but I don’t understand anything because my english is too bad to do it…

My HTML code addSwitchPort.html :

<form action="addSwitchPort.php" method="post">
<table>
    <tr>
        <td>Switch</td> 
        <td><input type="text" class='switchName' name="switchName"/></td>
    </tr>
    <tr>
        <td><input class="buttonIndex" type="submit" name='vlan' value="Add & vlan" style="width:200px"/></td>
    </tr>
</table>
</form>

My PHP code addSwitchPort.php :

<?php
$switchName = $_POST['switchName'];

echo $switchName;
echo '???';

$bra = addSwitchPort($switchName);

This is the code of addSwitchPort but there is no bug on this function because $switchName is empty

function addSwitchPort($switchName)
{
    global $conn;
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $switchID = getIDSwitch($switchName);
        try {
            $sql = 'INSERT INTO switchport (switchID) VALUES 
            ("'.$switchID.'"")';
            $conn->exec($sql);
            echo 'SUCCESS';
        } catch(PDOException $e) {
            echo $sql . "<br>" . $e->getMessage();
        }   

}

Do you know why the echo is empty ? There is no way because this is the right location !

Advertisement

Answer

The HTTP response status code 301 Moved Permanently is used for permanent URL redirection, meaning current links or records using the URL that the response is received for should be updated. The new URL should be provided in the Location field included with the response.

So, in your form declaration:

<form action="addSwitchPort.php" method="post">

Make you sure that addSwitchPort.php is in the same dir that addSwitchPort.html.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement