我有两个.php文件。第一个文件是contact.php,其中包含联系表单,另一个文件是contact_form.php,其中包含用于将数据发送到数据库的SQL和PHP语句。我的contact_form.php文件和数据库之间有成功的连接;但是,每当我在本地主机上的HTML表单中写入信息并执行“提交”时,我都会收到以下错误:
错误:找不到文件:views \ home \ contact_form.php.php
我有两个问题:
1)我将contact_form.php文件放在与我的contact.php文件相同的目录中,即** views \ home **那么为什么它会给我一个错误,它无法在该目录中找到该文件?
2)为什么在错误消息中我的contact_form.php文件有额外的.php结尾?
contact.php的代码:
<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>
contact_form.php:
<?php
define('DB_NAME', 'database_db');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$connection){
die('Database connection failed: ' . mysqli_connect_error());
}
$db_selected = mysqli_select_db($connection, DB_NAME);
if(!$db_selected){
die('Can\'t use ' .DB_NAME . ' : ' . mysqli_connect_error());
}
echo 'Connected successfully';
$name = @$_POST ['fullname'];
$phone = @$_POST ['phonenumber'];
$email = @$_POST ['emailaddress'];
$msg = @$_POST ['message'];
$sql = "INSERT INTO contact_form (fullname, phonenumber, emailaddress, message) VALUES ('$name', '$phone', '$email', '$msg')";
if (!mysqli_query($connection, $sql)){
die('Error: ' . mysqli_connect_error($connection));
}
?>
我知道SQL注入,一旦看到一切正常,就会对它进行处理。
的.htaccess
# 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]
答案 0 :(得分:1)
似乎有些东西(很可能是.htaccess)正在重写你的网址。也许它是故意的,例如,网址/home
实际上转到/home.php
。在这种情况下,您需要相应地修改表单操作:
action="contact_form"
更新
绝对是htaccess。最后三行。我不明白这是如何适合你在问题中表现出来的。因此,如果您肯定不使用那种重定向,请随意注释掉或删除这三行(无需更改操作URL)。否则,我最初的建议应该有效。