Error 404 when entering data into database using PHP with Wampserver

Asked

Viewed 178 times

-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 error "404" in my browser.

  • You must put the attr action of the form, for a php page, which will take the data and insert it into the database

  • thanks for the answer colleague, but why would I have to redirect the page? the insertion is done in: "if(isset($_POST["submit1"])) { mysqli_query($link, "INSERT INTO table1 values('$_POST[t1]', '$_POST[t2]')"); } "

  • Error occurs after insertion ?

  • error 404 as per image: [IMG]http://i65.tinypic.com/ip3yvd.png[/IMG]

  • Sorry, I edited unintentionally in the code, but in reality I am, including already edited the code in the quote, on the other hand the error persists :/

  • Consider reviewing your code line by line, and fix syntax errors first.

  • I notice that the default wampserver port is 3306, but the port shown in the page url when I try to run the code via phpStorm is 63342, could that be it? and how do I change it?

Show 2 more comments

1 answer

0


Let’s go in parts. When you install wampserver (in windows) a folder is created in C:\wampserver. In that folder is a call www (C:\wampserver\www) which is equivalent to you calling the url from the browser 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 briefcase C:\wampserver\www, you could access something like http://localhost/inserir.php and everything would work correctly.

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

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

  • My dear Juven_v, you nailed it! , too bad I can’t honor your response by being a beginner in this community, but that’s exactly it, my doubt was solved when I set up a manual interpreter for phpStorm. If anyone else has the same problem, this video: https://www.youtube.com/watch?v=953mNQ5KuBIhelped me!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.