日期:2014-05-17 浏览次数:20468 次
我在sae上搭建了一个个人简历的页面: 有兴趣的可以访问 http://671coder.sinaapp.com/
在做下面一个简单的留言板的时候,卡了我很久,虽然完全没用过php。。但是还是最后勉强写出来了。。。
主页面html是这样写的:
<div class="row row-contact" id="contact_row" style="display: block">
<article>
<h2 class="section-title">Contact Me</h2>
<p>This block can be hidden and only shown in <a class="zoom-html">a popup</a>.</p>
<div class="wrap-contact-form">
<form id="contacts" class="contact-form" action="/db/submitform.php" method="post">
<table class="info">
<tr>
<th><label for="contact_name">Name</label></th>
<td><input type="text" class="input-text" name="contact_name" id="contact_name" value="" maxlength="10"></td>
</tr>
<!-- start spam protection
<tr class="spam-protection">
<th><label>E-mail</label></th>
<td><input type="text" name="email" value=""></td>
</tr>
end -->
<tr>
<th><label for="contact_code">Security code</label></th>
<td><input type="text" class="input-text" name="contact_code" id="contact_code" maxlength="4"></td>
</tr>
<tr>
<th><label for="contact_message">Your Message</label></th>
<td><textarea id="contact_message" name="contact_message" maxlength="200"></textarea></td>
</tr>
<tr>
<th></th>
<td>
<input type="submit" class="input-submit" name="contact_send" value="Send">
<div class="on-success">
Thank You. The message was sent.
</div>
<!--
<div class="on-error">
A technical error occured. Message was not delivered. Please contact me over e-mail.
</div>
-->
</td>
</tr>
</table>
</form>
</div>
</article>
</div>后台的php是这样写的:
<?php
$name = $_POST['contact_name'];
$message = $_POST['contact_message'];
if (strlen($name) == 0 || strlen($message) == 0) {
?><script>
alert("Sorry, your name and your message can not be empty.");
window.history.back(-1);
</script><?
}
$m_notchar="$#@!%&*?<>";
$mysql = new SaeMysql();
$judge = true;
for ($i=0; $i<10; $i++) {
if (strpos($name, substr($m_notchar, $i, 1)) || strpos($message, substr($m_notchar, $i, 1)))
$judge = false;
}
if( $mysql->errno() != 0 ) {
die( "Error:" . $mysql->errmsg() );
} else if (!$judge) {
?><script>alert("Sorry, your message has illegal characters, please re-enter checked.");</script><?
} else {
$sql = &q