php 文件未使用 xampp 运行 [英] php file is not running using xampp
问题描述
我是 Web 开发的新手,我刚刚安装了 xampp.控制面板显示一切正常.所有服务都在运行.
I am a newbie in web development and I have just installed xampp. The control panel show everything is fine. All the services are running.
我使用 phpMyAdmin 在 mySQL 中创建了一个数据库,使用 phpMyAdmin 一切正常.我正在尝试制作一个简单的表格,这将使我能够在数据库表中添加数据.我的html表单和php代码如下.这两个文件都在 htdocs 文件夹中:
I have created a database in mySQL using the phpMyAdmin and everything is fine with phpMyAdmin. I am trying to make a simple form which will make me able to add data in database table. My html form and php code are as follows. Both files are in htdocs folder:
表单.html
<form action="signup.php" method="post">
Email: <input type="text" name="email"> <br>
Firstname: <input type="text" name="f_name"> <br>
Lastname: <input type="text" name="l_name"> <br>
Password: <input type="password" name="password"> <br>
Stream: <input type="text" name="stream"> <br>
<input type="submit">
</form>
</body>
</html>
注册.php:
$sql="INSERT INTO student (email,f_name,l_name,password,stream)
VALUES
('$_POST[email]','$_POST[f_name]','$_POST[l_name]','$_POST[password]','$_POST[stream]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
当我点击表单中的提交按钮时,我的浏览器 Google Chrome 会将我带到 file:///C:/xampp/htdocs/signup.php
并显示以下内容php 脚本而不是运行它.
When I click on the submit button in the form, my browser, Google Chrome, takes me to file:///C:/xampp/htdocs/signup.php
and shows the contents of php script instead of running it.
如果我手动输入地址栏 http://localhost/signup.php
脚本被执行,并且所有属性为空白的记录被插入到 student
表中.所以我的结论是php运行正常.
If i manually enter into the address bar http://localhost/signup.php
the script is executed and a record with all attributes blank is inserted into student
table. So m conclusion is that php is running properly.
如何在提交表单时运行 php 脚本?谢谢:)
How to run the php script when I submit my form? Thanks :)
推荐答案
你必须通过你的本地 Web 服务器调用你的 html 文件 http://localhost/form.html
否则你的基本路径是你的本地文件,就像您使用 file:///
看到的一样,但您的提交 URL 不正确.
You have to call your html file over your local Webserver http://localhost/form.html
otherwise your base path is your local file like you see with file:///
and your submit URL is incorrect.
这篇关于php 文件未使用 xampp 运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!