-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
– RickPariz
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]')"); } "
– John Jones
Error occurs after insertion ?
– RickPariz
error 404 as per image: [IMG]http://i65.tinypic.com/ip3yvd.png[/IMG]
– John Jones
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 :/
– John Jones
Consider reviewing your code line by line, and fix syntax errors first.
– MagicHat
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?
– John Jones