表单不在SQL数据库中填充

时间:2013-12-17 19:50:26

标签: php html sql forms

当用户选择提交时,我试图将一些数据从php表单填充到一个sql数据库中。然而,'animalClass'和'animalCommon'数据并没有填充;但其他数据填写得很好。首先,我将发布HTML / PHP代码,然后发布SQL db的一些屏幕截图。感谢您的关注和帮助。

$db = get_db_connection('swcrc');
    $db->connect();

    //Process status update form if submitted
    if(isset($_GET['admin_update']) && isset($_POST['request_id']) && 
       isset($_POST['status']) && $_POST['status'] != '')
    {
        $db->query("UPDATE dbo.Request SET status='%s' WHERE ID=%d", 
            $_POST['status'], 
            $_POST['request_id']);
        $db->query("INSERT INTO dbo.Response (request_ID, user_ID, complete, comment, response_date, animalClass, animalCommon) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s')",
            $_POST['request_id'], 
            $_POST['status_update_user_id'], 
            $_POST['status'], 
            $_POST['status_update_comments'],
            $_POST['date_completed'],
            $_POST['animalClass'],
            $_POST['animalCommon']);
        $msgs = "Status updated successfully.";
        $mode = "readonly";
    }
    //Process admin update form if submitted
    else if(isset($_POST['request_id']) && isset($_POST['completed']) && $_POST['completed'] != '')
    {
        $db->query("UPDATE dbo.Request SET status='%s' WHERE ID=%d", 
            $_POST['completed'], 
            $_POST['request_id']);
        $db->query("INSERT INTO dbo.Response (request_ID, user_ID, complete, comment, response_date, animalClass, animalCommon) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s')",
            $_POST['request_id'], 
            $_POST['completed_by_user_id'], 
            $_POST['completed'], 
            $_POST['not_completed'],
            $_POST['date_completed'],
            $_POST['animalClass'],
            $_POST['animalCommon']);
        $msgs = "Details updated successfully.";

接下来我将发布select语句代码:

<p>
<label for="animalClass">Class</label>
<select id = "animalClass" name="animalClass">
<option>Select a Class:</option>
<option value="Amphibians">Amphibians</option>
<option value="Birds">Birds</option>
<option value="Cnidarians">Cnidarians</option>
<option value="Fish">Fish</option>
<option value="Invertebrates">Invertebrates</option>
<option value="Mammals">Mammals</option>
<option value="Reptiles">Reptiles</option>
</select>
</p>
<p>
<label for="animalCommon">Common Name</label>
                          <select name="animalCommon" id="animalCommon">
                            <option>Select a Common Name:</option>
                         <?php
$db = get_db_connection('swcrc');
$db->connect();
$db->query("SELECT [Common Name] FROM dbo.All_Animals");
while($row = $db->fetch())
{
?>
   <option value="<?php echo $row['ID'];?>"><?php echo $row['Common Name'];?></option>
<?php 
}
?>
                            </select>
                            </p>

<p>
<label for="animalScientific">Scientific Name</label>
                          <select name="animalScientific" id="animalScientific">
                            <option>Select a Scientific Name:</option>
                         <?php
$db = get_db_connection('swcrc');
$db->connect();
$db->query("SELECT [Scientific Name] FROM dbo.All_Animals");
while($row = $db->fetch())
{
?>
   <option value="<?php echo $row['ID'];?>"><?php echo $row['Scientific Name'];?></option>
<?php 
}
?>
                            </select>
                            </p> 

最后,这是我在sql数据库中的结果的快照。再次感谢您的期待和希望回答。您将在图片中看到的问题是应填充所选数据的空白区域。 As you can see, nothing is populating the the third and second to last columns.

Form

0 个答案:

没有答案