数据成功提交到数据库时为什么会出错?

时间:2012-01-03 17:28:37

标签: php mysql

为什么呢?数据已成功提交到数据库,但我得到'错误'而不是确认它提交到mysql数据库?代码如下:

  <?
$sql="SELECT firstname FROM Users WHERE role = 'chairperson'";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["firstname"];
    $thing=$row["firstname"];
    $options.="<OPTION VALUE=\"$id\">".$thing; 
}
?>

<?
$sql="SELECT firstname FROM Users WHERE role = 'secretary'";
$result=mysql_query($sql);

$secretary="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["firstname"];
    $thing=$row["firstname"];
    $secretary.="<OPTION VALUE=\"$id\">".$thing; 
}
?>

<form action="meetingsinserted.php" method="post">

<table width="0" border="0">
  <tr>
    <td>      <label for="meeting">Title of Meeting: </label>
</td>
    <td><span id="sprytextfield1">
      <input type="text" name="title" id="title" />
      <span class="textfieldRequiredMsg">Give The Meeting A Title</span></span></td>
  </tr>
  <tr>
    <td>      <label for="chairperson">Chairperson:</label>
</td>
    <td><span id="spryselect1">
      <select name="chairperson" id="chairperson">
        <option>Choose Chairperson</option>
        <option value="0"><?=$options?></option>
      </select>
      <span class="selectRequiredMsg">You Must Choose A Chairperson For This Meeting</span></span></td>
  </tr>
  <tr>
    <td>      <label for="secretary">Secretary:</label>
</td>
    <td><span id="spryselect2">
      <select name="secretary" size="1" id="secretary">
              <option>Choose Secretary</option>
         <option value="0"><?=$secretary?></option>
      </select>
      <span class="selectRequiredMsg">You Must Choose A Secretary For This Meeting</span></span></td>
  </tr>
  <tr>
    <td>      <label for="tof">Terms of Ref: </label>
</td>
    <td><span id="sprytextarea1">
      <textarea name="tof" id="tof" cols="35" rows="5"></textarea>
      <span class="textareaRequiredMsg">What Is The Meeting About</span></span></td>
  </tr>
  <tr>
    <td>      <label for="occurances">Occurances:</label>
</td>
    <td><span id="sprytextfield2">
    <input type="text" name="occurances" id="occurances" />
    <span class="textfieldRequiredMsg">How Many Times Will This Occur Every Year</span><span class="textfieldInvalidFormatMsg">Please Enter Numbers Only</span></span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><br /><input name="" type="submit" value="Create Meeting" /></td>
  </tr>
</table>


</form>
会议插入页面如下:

<?php

$title = $_REQUEST['title'];
$chairperson = $_REQUEST['chairperson'];
$secretary = $_REQUEST['secretary'];
$tof = $_REQUEST['tof'];
$occurances = $_REQUEST['occurances'];

$con = mysql_connect("********","****","**********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('***', $con);

$sql="INSERT INTO Meetings (title, chairperson, secretary, tof, occurances) VALUES ('$title','$chairperson', '$secretary','$tof','$occurances')";

if (!mysql_query($sql,$con))
  {
      echo '<h1>Meeting Has Been Sent To Chairperson For Approval</h1>';
  }
  else 
  {
  die('Error: ' . mysql_error());
  }
?>

任何想法的家伙?感谢

1 个答案:

答案 0 :(得分:2)

因为你改变了你的条件:

if (!mysql_query($sql,$con))
  {
      echo '<h1>Meeting Has Been Sent To Chairperson For Approval</h1>';
  }
  else 
  {
  die('Error: ' . mysql_error());
  }