Error 404 when inserting data in bank using PHP with WampServer

-2

I have the following code that inserts in my DB a name and city using PHP.

<?php
$link = mysqli_connect("localhost", "root", "admin");
mysqli_select_db($link, "crud");
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form name="form1" action="" method="post">
        <table>
            <tr>
            <td>Insira o Nome</td>
            <td><input type="text" name="t1"</td>
            </tr>
            <tr>
                <td>Insira a Cidade</td>
                <td><input type="text" name="t2"</td>
            </tr>
            <tr>
                <td colspan="2" align="right"><input type="submit" name="submit1" value="Cadastrar"></td>
            </tr>
        </table>
</form>

<?php
if(isset($_POST["submit1"]))
{
    mysqli_query($link, "INSERT INTO table1 values('$_POST[t1]', '$_POST[t2]')");
}


?>
</body>
</html>

Every time I try to insert, I get the "404" error in my browser.

    
asked by anonymous 16.12.2017 / 14:07

1 answer

0

Let's break it down. When you install wampserver (on windows) a folder is created in C:\wampserver . In this folder there is a www ( C:\wampserver\www ) call that is equivalent to calling the browser to http://localhost (by default on port 80, which the browser omits, but would be something like http://localhost:80 ). So if you put your file, for example let's call inserir.php , inside the C:\wampserver\www folder, you could access the browser something like http://localhost/inserir.php and everything would work correctly.

The part where you say that the default port of the wampserver is 3306, you must be referring to the default port of the mysql database server.

For you to run the code directly from phpstorm some settings must be made. Some links on how to do these settings:

17.12.2017 / 18:37