2012-01-06 29 views
0

我在我的数据库中有一个名为议程表的表,它与另一个称为会议的表链接。我想通过表单编辑议程表,但我希望议程字段中的当前信息显示在Web表单上。无法从数据库中获取数据以显示在通过表单更新的字段中

<?php 
include 'library/connect.php'; 
$agenda_id = $_GET['agenda_id']; 
$result = mysql_query("SELECT agenda.*, meetings.meeting_id FROM agenda INNER JOIN meetings ON agenda.meetings = meetings.meeting_id WHERE agenda_id = '$agenda_id'"); 

$row = mysql_fetch_array($result); 
$meeting_id = $row['meeting_id']; 

?> 
    <form id="form1" name="form1" method="post" action="secretary_agendaSuccesful.php?agenda_id=<?php echo $agenda_id; ?>"> 
    <table width="666" border="1"> 
     <tr> 
     <td width="91">Subject:</td> 
     <td width="559"><span id="sprytextarea1"> 
      <label for="subject"></label> 
     <textarea name="subject" id="subject" cols="45" rows="5" value="<? echo $row['subject'] ?>"></textarea> 
      <span class="textareaRequiredMsg">A subject is required.</span></span></td> 
     </tr> 
     <tr> 
     <td>Duration:</td> 
     <td><span id="sprytextfield1"> 
     <label for="duration"></label> 
     <input type="text" name="duration" id="duration" value="<? echo $row['duration'] ?>"/> 
     <span class="textfieldRequiredMsg">duration in hours</span><span class="textfieldInvalidFormatMsg">Enter duration in hours</span></span></td> 
     </tr> 
     <td>&nbsp;</td> 
     <td><input type="submit" name="submitbtn" id="submitbtn" value="Submit" /></td> 
     </tr> 
    </table> 
    </form> 

这是从数据库中获取信息到域中的正确方法吗?

+0

您的代码对SQL注入攻击非常开放。您不应该直接将'$ _GET'变量(或*任何*变量)插入到查询中。请看看这个问题如何解决它,http://stackoverflow.com/questions/60174/best-way-to-stop-sql-injection-in-php – 2012-01-06 22:49:14

回答

0

这几乎是正确的方法
只有你需要的是使用htmlspecialchars()函数对显示值。

可能会有另一个问题 - 查询本身,它会阻止您的数据显示。

而且也有明显的SQL注入

使您的代码这样

$agenda_id = intval($_GET['agenda_id']); 
$query = "SELECT agenda.*, meetings.meeting_id FROM agenda 
      INNER JOIN meetings ON agenda.meetings = meetings.meeting_id 
      WHERE agenda_id = $agenda_id"; 
$result = mysql_query($query) or trigger_error(mysql_error()." ".$query); 

,看看它是否会显示任何错误

编辑
只注意到你正在使用value参数为<textarea>标签。这个标签与其他标签有不同的用法。

+0

注意:未知列'agenda.meetings' in'on clause'SELECT议程。*,meetings.meeting_id FROM议程内部联接会议ON agenda.meetings = meetings.meeting_id WHERE agenda_id = 16在E:\ webareas \ bj115 \ year3 \ EWSD \ MeetingSystem \ secretary_editAgenda.php在线31 ... <<<<我得到那个错误 – user1130533 2012-01-06 22:58:44

+0

看到错误报告如何帮助?始终以这种方式运行查询并收到所有数据库错误的通知 – 2012-01-06 23:20:26

相关问题