我知道这个问题可能听起来很愚蠢,但我需要你的帮助。我的问题是我想在表单内打印出这个“错误”消息,而不是在表单外打印出来。目前,“错误”消息打印在 .
代码如下:
过程:
if(!$name || !$email || !$comment){
//if not display an error message
echo "<center>All fields are required</center>";
}
else
{
mysql_select_db($database_connection, $connection);
$insert_query = sprintf("INSERT INTO contacts (name, email, comment, date, ip) VALUES (%s, %s, %s, NOW(), %s)",
sanitize($name, "text"),
sanitize($email, "text"),
sanitize($comment, "text"),
sanitize($ip, "text"));
$result = mysql_query($insert_query, $connection) or die(mysql_error());
}
形式:
<form id="contact" name="contact" action="index.php" method="post">
<fieldset>
<li><input class="rounded" type="text" name="name" id="name" placeholder="Your Name" required />
</li>
<li>
<input class="rounded" type="text" name="email" id="email" placeholder="Your Email" required />
</li>
<li>
<textarea class="rounded" name="comment" id="comment" cols="35" rows="6" placeholder="Your Message" required ></textarea>
</li>
<input type="hidden" id="action" name="action" value="submitform" />
<li>
<input id="submit" name="submit" type="submit" value="Send" class="submitform" />
</li>
</fieldset>
</form>
任何帮助将不胜感激!