两文件 PHP 联系表
pswindex.php 部分似乎工作正常,但处理程序抛出内部服务器错误(500)。
索引.php
<div id="contact">
<h1>Contact us</h1>
<form id="ContactForm" method="post" action="submit.php">
<p>
<label>Name<span>(optional)</span></label>
<input id="name" name="name" class="inplaceError" maxlength="120" type="text" autocomplete="on"/>`enter code here`
<span class="error" style="display:none;"></span>
</p>
<p>
<label>Email<span>(optional)</span></label>
<input id="email" name="email" type="text" />
</p>
<p>
<label>Subject<span>(optional)</span></label>
<input id="website" name="website" />
</p>
<p>
<label>Your message<br /> <span>700 characters allowed</span></label>
<textarea id="message" name="message" cols="6" rows="5"></textarea>
</p>
<p class="submit">
<input id="send" type="submit" value="Submit" name="submit"/>
<span id="loader" class="loader" style="display:none;"></span>
</p>
<input id="newcontact" name="newcontact" type="hidden" value="1"></input>
</form>
submit.php -->
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website']; //subject
$message = $_POST['message'];
$connection = mysql_connect ("localhost", "root", "pswd") or die ('DB connection fail:' .mysql_error());
mysql_select_db ("contactform");
$query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES ('NULL','$name','$email','$sub','$msg','NULL')";
//good to know about the quotes, but the page still insist there's an error
mysql_query($query) or die ('Error uploading DB');
mysql_close($connection);
echo "<span id="success_message" class="success">YAY! It worked.</span>";
} else {
echo "<span class='error'>Try again.</span>";
}
pswThe index.php part seems to work fine, but the handler throws a internal server error (500).
index.php
<div id="contact">
<h1>Contact us</h1>
<form id="ContactForm" method="post" action="submit.php">
<p>
<label>Name<span>(optional)</span></label>
<input id="name" name="name" class="inplaceError" maxlength="120" type="text" autocomplete="on"/>`enter code here`
<span class="error" style="display:none;"></span>
</p>
<p>
<label>Email<span>(optional)</span></label>
<input id="email" name="email" type="text" />
</p>
<p>
<label>Subject<span>(optional)</span></label>
<input id="website" name="website" />
</p>
<p>
<label>Your message<br /> <span>700 characters allowed</span></label>
<textarea id="message" name="message" cols="6" rows="5"></textarea>
</p>
<p class="submit">
<input id="send" type="submit" value="Submit" name="submit"/>
<span id="loader" class="loader" style="display:none;"></span>
</p>
<input id="newcontact" name="newcontact" type="hidden" value="1"></input>
</form>
submit.php -->
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website']; //subject
$message = $_POST['message'];
$connection = mysql_connect ("localhost", "root", "pswd") or die ('DB connection fail:' .mysql_error());
mysql_select_db ("contactform");
$query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES ('NULL','$name','$email','$sub','$msg','NULL')";
//good to know about the quotes, but the page still insist there's an error
mysql_query($query) or die ('Error uploading DB');
mysql_close($connection);
echo "<span id="success_message" class="success">YAY! It worked.</span>";
} else {
echo "<span class='error'>Try again.</span>";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的查询字符串有错误。它应该看起来像
双引号正在分解你的字符串,并且不同的部分没有被连接。
I think you've got an error with your query string. It should look like
The double quotes were breaking up your string, and the different parts weren't being concatenated.
正如米克西托提到的。您需要删除 NULL 周围的引号。
假设您已设置 mysql 表,因此
added_date
字段是 mysql 时间戳格式,尝试在表中输入'NULL'
将导致 mysql 错误。还要确保 mysql 表允许在
pk_contact
和added_date
字段中输入空值。As Mikecito mentioned. You'll want to remove the quotes around NULL.
Assuming you have set you mysql table so the
added_date
field is a mysql timestamp format, attempting to enter'NULL'
into the table will result in a mysql error.Also make sure the mysql table allows null values to be entered into the
pk_contact
andadded_date
fields.