I tried a lot to find a solution to this problem but I am not sure what's the actual issue here. I have done similar exercises before and it worked perfect but this code is not working at all.
<?php
if(isset($_POST['submit']))
{
$database=mysqli_connect('localhost','root','','manager')
or die ('didn\'t work');
$in=$_POST['income'];
$sv=$_POST['savings'];
echo $in;
echo $sv;
mysqli_query($database,"USE manager");
mysqli_query($database,"INSERT INTO manage (m1,m2) VALUES ('$_POST[income]','$_POST[savings]')");
mysqli_close($database);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Enter your monthly income
<input type="text" name="income" >
Enter your target savings
<input type="text" name="savings" >
<input type="submit" >
</form>
Ruled Out Possibilities:
- Form is not getting submitted
I used
method='get'
and confirmed that form is getting submitted. - Not an issue with db name or table name. Figured this out because no such error was shown and content in 'die()' wasn't echoed.
What I think is the issue?
Control is not moving inside the
if block
even if form is submitted. I am not able to figure out why this is happening. Other forms are working perfect. The problem exists with this code only. I learned the code from online tutorials and has used it before.