【发布时间】:2014-02-16 10:06:13
【问题描述】:
我正在编写一个简单的电子邮件系统,并且在将其保存到草稿时遇到了逻辑上的复杂性。我已经创建了一个用于撰写邮件的文件。
<?php
include ('connection.php');
$sender = $_POST['sender'];
$sendto = $_POST['sendto'];
$title = $_POST['title'];
$body = $_POST['body'];
$date = date("Y-m-d H:i:s");
$string = strstr($sendto, '@');
if(!empty($_POST) and ($string != '@raymart.com')) {
(mysql_query("INSERT INTO sent (sender, sendto, title, body, date) VALUES ('".$sender."', '".$sendto."', '".$title."', '".$body."', '".$date."')") or die(mysql_error())); {
$message = $body . "\r\n";
$message .= "Date sent: ". $date;
mail($sendto,$title,$message,$sender);
echo 'Email successfully sent!';
}
}
if(!empty($_POST) and ($string == '@raymart.com')) {
(mysql_query("INSERT INTO sent (sender, sendto, title, body, date) VALUES ('".$sender."', '".$sendto."', '".$title."', '".$body."', '".$date."')") or die(mysql_error()));
(mysql_query("INSERT INTO inbox (sendto, sender, title, body, date) VALUES ('".$sendto."', '".$sender."', '".$title."', '".$body."', '".$date."')") or die(mysql_error()));
{
echo 'Email successfully sent!';
}
}
?>
<div class="container">
<form class="form-horizontal" method="post">
<fieldset>
<!-- Form Name -->
<legend>Compose Mail</legend>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="sender">From: </label>
<div class="controls">
<input id="sender" name="sender" placeholder="Your email" class="input-xlarge cmps" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="sendto">Send To: </label>
<div class="controls">
<input id="sendto" name="sendto" placeholder="Send To" class="input-xlarge cmps" type="text">
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="title">Title: </label>
<div class="controls">
<input id="title" name="title" placeholder="Title/Subject" class="input-xlarge cmps" type="text">
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="body">Message: </label>
<div class="controls">
<textarea id="body" name="body" class="cmps"></textarea>
</div>
</div>
<button type="submit" id="button" class="btn btn-success">Send!</button>
<a href="save.php" class="btn-danger btn">Save to drafts</a>
</fieldset>
</form>
</div>
我还创建了动作.. 即“save.php”
<?php
include ('connection.php');
$sender = $_POST['sender'];
$sendto = $_POST['sendto'];
$title = $_POST['title'];
$body = $_POST['body'];
$date = date("Y-m-d H:i:s");
$newURL = "drafts.php";
mysql_query("INSERT INTO draft (sender, sendto, title, body, date) VALUES ('".$sender."', '".$sendto."', '".$title."', '".$body."', '".$date."')") or die(mysql_error());
$message = $body . "\r\n";
$message .= "Date sent: ". $date;
echo 'Email successfully sent!';
header('Location: '.$newURL);
?>
它确实向草稿表添加了一个条目,但没有值。小伙伴们一定有什么问题?任何帮助将不胜感激。
【问题讨论】:
-
你对 SQL 注入攻击持开放态度......而且你的
<form>没有action属性,所以它永远不会提交给save.php,它只会提交给自己. -
您的脚本对 SQL 注入开放。至少对查询字符串中的所有变量使用 mysql_real_escape_string($_POST['sender'])。
-
感谢您的信息和提示!稍后将更新此线程:) 谢谢!