Reputation: 19
I am trying to add new elements to my mysql table through html So far I've got this
<form action="MyCurrentFile.php" method="post" >
Artist Name
<input type="text" name="addingnewelement" <br/>
<input type = "submit" name = "Submit" />
</form>
and this
<?php
if (isset($_POST['submit'])) {
$addingelement=$_POST['addingnewelement'];
$mysqli->select_db("names", $names);
echo("this code is running");
$sql='INSERT INTO names (nameValue) VALUES ('.$addingelement.')';
$mysqli->query($sql, $mysqli);
$mysqli->close($mysqli);
}
?>
Is there anything on my syntax wrong? the code does not give me any error, all that happens is that I press my button to update with my input but nothing happens.
Upvotes: 1
Views: 36
Reputation: 9
the submit button name is Submit with capital S but you are using isset($_POST['submit']) with small s
correct this. it will work..
and also if $sql='INSERT INTO names (nameValue) VALUES ('.$addingelement.')'; not working then try
$sql="INSERT INTO names (nameValue) VALUES ('".$addingelement."')";
Upvotes: 0
Reputation: 15509
you need to put hte artist name as the label and close the input, and make the name of the submit button the same as in your other page.
<form action="MyCurrentFile.php" method="post" >
<label for="artistName">Artist Name</label>
<input type="text" id="artistName" name="addingnewelement" value=""/>
<input type="submit" name="submit" value="submit"/>
</form>
also your sql query is wrong - it should be:
$sql="INSERT INTO names (nameValue) VALUES ('".$addingelement."')";
Upvotes: 1
Reputation: 9
Your SQL query is wrong. Please replace this live:
$sql="INSERT INTO names (nameValue) VALUES ('$addingelement')";
Upvotes: 0