Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6809621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:06:28+00:00 2026-05-26T20:06:28+00:00

Having trouble where I think I need to provide most of my code to

  • 0

Having trouble where I think I need to provide most of my code to see what is happening. Trying to output a simple table of cameras. They are stored as part of a form which a user can change and hit the apply button. The changes should update the db. The problem is that when I hit apply it doesn’t update any of the rows. The exception is the very last row (last camera in the list).

As you can see I echo certain variables and they seem fine. Completely confused…

<?php 
// Dont allow direct linking
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
//get current user
$user =& JFactory::getUser();
// get a reference to the database
$db = &JFactory::getDBO();

if (isset($_POST['apply_changes'])) {

    //process changes to camera options     
    $camera_id = (int) $_POST['camera_id'];
    echo "CAMERA ID ".$camera_id;
    $camera_status = check_input($_POST['camera_status']);
    echo "CAMERA STATUS ".$camera_status;
    $camera_name = check_input($_POST['camera_name']);
    $camera_quality = check_input($_POST['camera_quality']);

    $query_insert_camera = 'UPDATE `#__cameras` SET `camera_status` ="'.$camera_status.'" WHERE `camera_id`='.$camera_id;
    echo "CAMERA query ".$query_insert_camera;
    $db->setQuery($query_insert_camera);
    $db->query();
}

function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
    echo $myError;
    exit();
}   

echo "<html>";
echo "<head>";

?>

<script type="text/javascript">
function oncameraSubmit(camera_id)
{
 //TODO get camera name i.e.  "Apply changes to <camera name>"
  document.active_cameras.camera_id.value = camera_id;
  return confirm('Apply changes?');
}
</script>
<?php
$query_camera_name = "SELECT camera_id, camera_name, camera_status, camera_quality, camera_hash, camera_type FROM #__cameras WHERE user_id=".$user->id." AND camera_status!='DELETED'";
$db->setQuery($query_camera_name);
//get number of cameras so we can build the table accordingly
$db->query();
$num_rows = $db->getNumRows();
// We can use array names with loadAssocList.
$result_cameras = $db->loadAssocList(); 

echo "</head>";
echo "<body>";

//check if we have cameras running (basically someone logged in)
if (!isset($result_cameras))
{
    //TODO check if query failed
}
else 
{

    if ($num_rows == 0)
    {           
        echo '<b><i><center>You currently have no cameras setup.  Add a Camera below.</center></i></b>';
    }
    else
    {
        ?>
        <form name="active_cameras" action="<?php htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST">
        <input type="hidden" name="camera_id" value="" />
        <table id="webcam-table">
        <thead>
            <tr>
                <th>Camera Type</th>
                <th>Name</th>
                <th>Quality</th>
                <th>Status</th>
                <th>Camera Actions</th>
            </tr>
        </thead>
        <tbody>
<?php
        for($i=0;$i<$num_rows;$i++)
        {

            //camera_status
            if ($result_cameras[$i]["camera_status"] == "ENABLED")
            {
                $enabled_option =  "value='ENABLED' selected='selected'"; 
                $disabled_option = "value='DISABLED'";
            }
            else
            {
                $enabled_option =  "value='ENABLED'";
                $disabled_option = "value='DISABLED' selected='selected'";
            }

            //camera_quality
            if ($result_cameras[$i]["camera_quality"] == "HIGH")
            {
                $high_option =  "value='HIGH' selected='selected'"; 
                $medium_option = "value='MEDIUM'";
                $mobile_option =  "value='MOBILE'";
            }
            else if ($result_cameras[$i]["camera_quality"] == "MEDIUM")
            {
                $high_option =  "value='HIGH'";
                $medium_option = "value='MEDIUM' selected='selected'";
                $mobile_option =  "value='MOBILE'";
            }
            else if ($result_cameras[$i]["camera_quality"] == "MOBILE")
            {
                $high_option =  "value='HIGH'";
                $medium_option = "value='MEDIUM'";
                $mobile_option =  "value='MOBILE' selected='selected'";
            }
            else
            {
                //TODO proper logging
            }

            //camera_type
            if ($result_cameras[$i]["camera_type"] == "WEBCAM")
            {
                $webcam =  "value='WEBCAM' selected='selected'"; 
                $axis = "value='AXIS'";
                $other =  "value='IPCAM'";
            }
            else if ($result_cameras[$i]["camera_type"] == "AXIS")
            {
                $webcam =  "value='WEBCAM'";
                $axis = "value='AXIS' selected='selected'";
                $other =  "value='IPCAM'";
            }
            else if ($result_cameras[$i]["camera_type"] == "IPCAM")
            {
                $webcam =  "value='WEBCAM'";
                $axis = "value='AXIS'";
                $other =  "value='IPCAM' selected='selected'";
            }
            else
            {
                //TODO proper logging
            }
            echo $result_cameras[$i]["camera_id"];

?> 

            <tr>
                <td>
                    <?php echo $result_cameras[$i]["camera_type"] ?>
                </td>
                <td>
                <input type="text" size="32" maxlength="64" name="camera_name" value="<?php echo $result_cameras[$i]["camera_name"]; ?>" />
                </td>
                <td>
                    <select name="camera_quality">
                    <option <?php echo $high_option; ?>>High</option>
                    <option <?php echo $medium_option; ?>>Medium</option>
                    <option <?php echo $mobile_option; ?>>Mobile</option>
                    </select>
                </td>
                <td>
                    <select name="camera_status">
                    <option <?php echo $enabled_option; ?>>Enabled</option>
                    <option <?php echo $disabled_option; ?>>Disabled</option>
                    </select>
                </td>
                <td>
                    <input type="submit" name="apply_changes" value="Apply" onClick="oncameraSubmit(<?php echo $result_cameras[$i]["camera_id"]; ?>);"/>
                    &nbsp;&nbsp;&nbsp;
                    <input type="submit" name="delete" value="Delete" onClick="oncameraDelete(<?php echo $result_cameras[$i]["camera_id"]; ?>);"/>
                    &nbsp;&nbsp;&nbsp;
                    <input type="submit" name="video" value="Launch" onClick="oncameraLaunch(<?php echo $result_cameras[$i]["camera_id"]; ?>);"/>

                </td>
            </tr>

            <?php
        }

        echo "</tbody>";
        echo "</table>";
        echo "</form>";
    }
}


echo "</body>";
echo "</html>";

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:06:29+00:00Added an answer on May 26, 2026 at 8:06 pm

    Update query should be (Use single quote for non-numeric value),

    $query_insert_camera ="UPDATE `#__cameras` 
         SET `camera_status` ='$camera_status' WHERE `camera_id`=$camera_id";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do a seemingly simple thing, but having trouble accomplishing it.
I'm having some trouble keeping objects in a vector, and I think I need
I think I am having trouble visualizing what code goes where and what requests
I'm having trouble using newly installed gems - I think there must be something
I'm having trouble with displaying image from db. I think that method for saving
I think know how to do this in C# but I'm having syntax trouble
Having trouble with each function... Will try to explain by example... In my code,
Having trouble accessing javascript code in a mixed html/js ajax response. jQuery ajax doc
Having trouble understanding how to filter an images table by tag information in a
I'm having trouble finding a simple statement to skip the duplicates for this recursive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.