This question already has an answer here:
I have searched an all answers I found I can't get to work.
I am trying to create a form that adds a row to my database.
add.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Street Form</title>
</head>
<body>
<form onSubmit="php/insert.php" method="post">
<p>
<label for="streetname">Street Name:</label>
<input type="text" name="streetname" id="streetname">
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
insert.php
<?php
include 'php/connect.php
// attempt insert query execution
$sql = "INSERT INTO streets (name) VALUES ($_POST['streetname'])";
mysql_query($sql);
// close connection
mysqli_close($link);
?>
I know my connect.php works because I used it to display a random row from my DB
I'm still VERY new to SQL so I know it's a simple fix but not sure where.
I'd love a form that could add 5 values at once from 5 input fields but that is further down the road
Aucun commentaire:
Enregistrer un commentaire