1

I am trying to populate some data from a php form into a sql database when the user selects submit. However, the 'animalClass' and 'animalCommon' data is not populating; however the other data is populating fine. First I will post the HTML/PHP code and then some screen shots of the SQL db. Thank you for looking and the assistance.

$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.";

Next I will post the select statement code:

<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> 

And finally here is a snap shot of my results in my sql database. Thank you again for looking and hopefully answering. The issue that you will see in the picture is the empty spaces where the selected data should be populated. As you can see, nothing is populating the the third and second to last columns.

Form

17
  • I'm curious, why SELECT [Common Name] and SELECT [Scientific Name] ? If you're actually using that syntax, am not entirely sure that's valid. And if that's your colum names and contain spaces, then you should be using backticks instead of brackets. Dec 17, 2013 at 19:58
  • The brackets work fine, I have tested them all in SQL and they pull my desired information. For some reason if I use anything but the brackets I do not get any information pulled. Thank you for the response.
    – vector
    Dec 17, 2013 at 20:08
  • Testing in SQL and on a LIVE server are not the same animal. Syntax is a bit different. Dec 17, 2013 at 20:11
  • When I SELECT "Common Name" it pulls all the different common name's from the "Common Name" column.
    – vector
    Dec 17, 2013 at 20:14
  • Hahaha, I like the 'same animal' pun. I'll give the back tics a try and report back promptly.
    – vector
    Dec 17, 2013 at 20:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.