I have installed lamp in Ubuntu 12.04 using these commands:
$ sudo apt-get install tasksel
and
$ sudo tasksel install lamp-server
and run the following .php file in browser and it was executed by updating database
<?php
$con=mysqli_connect("localhost","root","passwd","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin',35)");
mysqli_query($con,"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire',33)");
mysqli_close($con);
?>
But when I use a .html file to connect a .php file and update mysql database the .php does not execute and want to save in a folder (Download folder as default). The .html file is:
<html>
<body>
<form action="/var/www/insert.php" method="post">
Firstname: <input type="text" name="firstname">
Lastname: <input type="text" name="lastname">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html>
and the insert.php file is:
<?php
$con=mysqli_connect("localhost","root","passwd","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
PLEASE HELP!
SOLVED! I just modified the part of the html file to,
<form action="http://localhost/insert.php" method="post">