Note that there are some explanatory texts on larger screens.

plurals
  1. POform submit not working
    primarykey
    data
    text
    <p>I have a table that prints out all available cameras. It uses a form to change these settings. The problem is that the form only updates the last camera in the entry. In other words if I change the form and hit "Apply" for the last camera in the list it will work. If I change the form for any other camera in this list it changes the one to have the same settings as the last camera in the list. There are no issues with any values as far as I can tell. </p> <p>Sorry for the long dump here, but without being able to narrow down the problem I thought I should include the bulk of it:</p> <pre><code>// Dont allow direct linking defined('_JEXEC') or die('Direct Access to this location is not allowed.'); //get current user $user =&amp; JFactory::getUser(); // get a reference to the database $db = &amp;JFactory::getDBO(); $query_camera_name = "SELECT camera_id, camera_name, camera_status, camera_quality, camera_hash, camera_type FROM #__cameras WHERE user_id=".$user-&gt;id." AND camera_status!='DELETED'"; $db-&gt;setQuery($query_camera_name); //get number of cameras so we can build the table accordingly $db-&gt;query(); $num_rows = $db-&gt;getNumRows(); // We can use array names with loadAssocList. $result_cameras = $db-&gt;loadAssocList(); if (isset($_POST['apply_changes'])) { //process changes to camera options $camera_id = $_POST['camera_id']; $camera_status = check_input($_POST['camera_status']); $camera_name = check_input($_POST['camera_name'], "You entered an empty camera name. Enter another name and apply changes."); $camera_quality = check_input($_POST['camera_quality']); $query_insert_camera = 'UPDATE `#__cameras` SET `camera_status` ="'.$camera_status.'", `camera_name` ="'.$camera_name.'", `camera_quality` ="'.$camera_quality.'" WHERE `camera_id`='.$camera_id; $db-&gt;setQuery($query_insert_camera); $db-&gt;query(); header("location: " . $_SERVER['REQUEST_URI']); } echo "&lt;html&gt;"; echo "&lt;head&gt;"; &lt;link href="dashboard/webcam_widget.css" rel="stylesheet" type="text/css" /&gt; &lt;script type="text/javascript"&gt; function oncameraSubmit(camera_id) { document.active_cameras.camera_id.value = camera_id; return confirm('Apply changes?'); } &lt;/script&gt; &lt;?php echo "&lt;/head&gt;"; echo "&lt;body&gt;"; if (!isset($result_cameras)) { //TODO } else { if ($num_rows == 0) { echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;You currently have no cameras setup. Add a Camera below.&lt;/center&gt;&lt;/i&gt;&lt;/b&gt;'; } else { ?&gt; &lt;form name="active_cameras" action="&lt;?php htmlentities($_SERVER['REQUEST_URI']); ?&gt;" method="POST"&gt; &lt;input type="hidden" name="camera_id" value="" /&gt; &lt;table id="webcam-table"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Camera Type&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Quality&lt;/th&gt; &lt;th&gt;Status&lt;/th&gt; &lt;th&gt;Camera Actions&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php for($i=0;$i&lt;$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 } ?&gt; &lt;tr&gt; &lt;td&gt; &lt;select name="camera_type"&gt; &lt;option &lt;?php echo $webcam; ?&gt;&gt;Webcam&lt;/option&gt; &lt;option &lt;?php echo $axis; ?&gt;&gt;AXIS&lt;/option&gt; &lt;option &lt;?php echo $other; ?&gt;&gt;Other&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="text" size="32" maxlength="64" name="camera_name" value="&lt;?php echo $result_cameras[$i]["camera_name"]; ?&gt;" /&gt; &lt;/td&gt; &lt;td&gt; &lt;select name="camera_quality"&gt; &lt;option &lt;?php echo $high_option; ?&gt;&gt;High&lt;/option&gt; &lt;option &lt;?php echo $medium_option; ?&gt;&gt;Medium&lt;/option&gt; &lt;option &lt;?php echo $mobile_option; ?&gt;&gt;Mobile&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;select name="camera_status"&gt; &lt;option &lt;?php echo $enabled_option; ?&gt;&gt;Enabled&lt;/option&gt; &lt;option &lt;?php echo $disabled_option; ?&gt;&gt;Disabled&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input type="submit" name="apply_changes" value="Apply" onClick="javascript:return oncameraSubmit(&lt;?php echo $result_cameras[$i]["camera_id"]; ?&gt;);"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } echo "&lt;/tbody&gt;"; echo "&lt;/table&gt;"; echo "&lt;/form&gt;"; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload