Having issues on inserting data into database from table in php, shows data inserted successfully but data not shown on phpmyadmin. I’m using wamp server on this project . please help me overcome this problem guys….
CODE:-
<?php
$host = 'localhost:3306';
$user = 'root';
$pass = '';
$conn = mysqli_connect($host, $user, $pass);
?>
<html>
<head></head>
<body>
<center>
<form method="POST">
<label> Firstname </label>
<input type="text" name="name" placeholder= "Name" size="15" required /> </br></br>
<label> Salary </label>
<input type="number" name="salary" placeholder= "salary" size="15" required /> </br></br>
<center>
<button type="submit" name="submit" id="submit" class="submit"><b>Submit</b></button>
</center>
</form>
</center>
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
{
echo $name;
}
$salary=$_POST['salary'];
{
echo $salary;
}
$sql = 'INSERT INTO emp5(name,emp_salary) VALUES ("$name", "$salary")';
}
?>
</body>
</html>
2
Answers
First you need to add one more line in top of the page like :
Then you need to execute the query like :
after the $sql line add this :
As Daniel pointed out you’re missing your query execution, as is you’re just saving your query as a variable, and you’re missing one parameter in your connection.
I would add the following:
Connection:
Query: