I dont have previous experience with PHP or SQL so i didnt quite catch everything and i have done this by previous various templates/examples, i manage to connect my form to database but it creates record on load before i enter data and press submit and i cant figure out why, also when i fill form and press submit, it takes me to home page should it do that way (and does not fill in data in table), here is code and thank you in advance!!!
<html>
<body>
<?php
$servername = "10.253.---.--";
$username = "intranet";
$password = "----";
$dbname = "intranet";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO AdresarGIS (Adresa, Broj, Mesto, Agent, Komentar)
VALUES ('$_POST[Adresa]','$_POST[Broj]','$_POST[Mesto]','$_POST[Agent]','$_POST[Komentar]' )";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
<label for="Adresa">Adresa</label><br/>
<input type="text" name="Adresa" />
</p>
<p>
<label for="Broj">Broj</label><br/>
<input type="text" name="Broj" />
</p>
<p>
<label for="Mesto">Mesto</label><br/>
<input type="text" name="Mesto" />
</p>
<p>
<label for="Agent">Agent</label><br/>
<input type="text" name="Agent" />
</p>
<p>
<label for="Komentar">Komentar</label><br/>
<input type="text" name="Komentar" />
</p>
<p>
<input type="submit" name="submit" value="Pošalji" />
</p>
</form>
</body>
</html>