我使用以下命令在 Ubuntu 12.04 中安装了灯:
$ sudo apt-get install tasksel
和
$ sudo tasksel install lamp-server
并在浏览器中运行以下 .php 文件,它是通过更新数据库来执行的
<?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);
?>
但是当我使用 .html 文件连接 .php 文件并更新 mysql 数据库时,.php 不会执行并希望保存在文件夹中(默认为下载文件夹)。.html 文件是:
<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>
insert.php 文件是:
<?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);
?>
请帮忙!