Php 为什么';我的HTML表单不能将数据提交到MySQL数据库吗?
我有两个.php文件。第一个文件是contact.php,它包含一个contact表单,另一个文件是contact_form.php,它包含将数据发送到数据库的SQL和php语句。我的contact_form.php文件与数据库成功连接;但是,每当我在本地主机上的HTML表单中写入信息并执行“提交”操作时,就会出现以下错误: 错误:找不到文件:views\home\contact\u form.php.php 我有两个问题: 1) 我的contact\u form.php文件与contact.php文件位于同一目录下,即**views\home**,那么为什么它会给我一个错误,即无法在该目录中找到该文件 2) 为什么在错误消息中我的contact_form.php文件有额外的.php结尾 contact.php的代码:Php 为什么';我的HTML表单不能将数据提交到MySQL数据库吗?,php,mysql,Php,Mysql,我有两个.php文件。第一个文件是contact.php,它包含一个contact表单,另一个文件是contact_form.php,它包含将数据发送到数据库的SQL和php语句。我的contact_form.php文件与数据库成功连接;但是,每当我在本地主机上的HTML表单中写入信息并执行“提交”操作时,就会出现以下错误: 错误:找不到文件:views\home\contact\u form.php.php 我有两个问题: 1) 我的contact\u form.php文件与contact.p
<form class="well" id="contactForm" name="sendMsg" novalidate="" action="contact_form.php" method="post">
<div class="control-group">
<div class="controls">
<input class="form-control" name="fullname" id="name" type="text" placeholder="Full Name" required="" data-validation-required-message="Please enter your name" />
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="form-control" name="phonenumber" id="phone" type="text" placeholder="Phone Number" required="" data-validation-required-message="Please enter your phone number" />
</div>
</div>
<div class="control-group">
<div class="controls">
<input class="form-control" name="emailaddress" id="email-address" type="email" placeholder="Email Address" required="" data-validation-required-message="Please enter your email" />
</div>
</div>
<div class="control-group">
<div class="controls">
<textarea rows="6" class="form-control" name="message" id="msg" type="msg" placeholder="Enter detailed question/concern, and we will get back to you." required="" data-validation-required-message="Please enter your question/concern"></textarea>
</div>
</div>
<div class="control-group">
<div class="controls submit-btn">
<button class="btn btn-primary" type="submit" value="Submit">Submit</button>
</div>
</div>
</form>
</div>
似乎有什么东西(很可能是.htaccess)正在重写您的URL。例如,可能是有意让url/home
实际转到/home.php
。在这种情况下,您需要相应地修改表单操作:
action="contact_form"
更新
这绝对是一个好机会。最后三行。我看不出这与你在问题中所展示的内容有什么关系。因此,如果您肯定没有使用这种重定向,请随意注释或删除这三行(无需更改操作url)。否则,我最初的建议应该会起作用。您可以向我们展示您的htaccess文件吗?在Chrome中打开此文件,打开开发人员工具并转到网络选项卡。当您提交表单时,请注意它的功能。它是否显示重定向?如果是重定向,我会查看.htaccess文件。我通过将其更改为action=“contact_form”来修复它,并修复了错误。现在,当我转到数据库时,我可以看到表中存储的数据。我感谢您的帮助,感谢您向我解释.htaccess中的错误,因为我正在调查,无法理解错误。不客气,我很高兴我能提供帮助。小心那些URL。
# EmagidPHP .htaccess
# Every website must have this file in its root web folder
Options +FollowSymlinks
RewriteEngine on
# Apache must be compiled with gzip or deflate for transmission
# compression to work for the following file types
# AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
# AddOutputFilterByType DEFLATE application/x-javascript
# application/javascript text/javascript text/x-js text/x-javascript
# AddOutputFilter DEFLATE js css htm html xml
# Missing favicon should not cause SkyPHP to load
RewriteRule ^favicon\.ico - [L]
# If the requested file or folder is not found, SkyPHP will check multiple codebases for the correct file
# Also, we are blocking php files that are in the pages folder from being accessed directly
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} /pages/(.*)\.php$
RewriteRule ^(.+)$ /mywebsite/index.php/$1 [L]
action="contact_form"