0
所以我有一個表,我加載複選框的值。點擊複選框後,我使用提交按鈕將它們保存到數據庫中。但是目前我只能一次保存一行?我需要能夠將所有點擊的複選框保存到數據庫中插入多個複選框到數據庫Html Php
例如,我有5行。如果選中第2行和第3行的複選框,則應將其保存到數據庫中,但現在只有最後一次單擊(第3行)被保存到數據庫中。 繼承人到目前爲止我的代碼
PHP的連接代碼
<?php
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query->select($db->quoteName(array('CV_ID', 'Classifier', 'Value')));
$query->from($db->quoteName('classvalues'));
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
?>
加載表複選框代碼
<form name="names" id="names" action="<?php echo JURI::current(); ?>" method="post">
<table border="5",th,td, cellspacing="5", cellpadding="5", width="500", align="left">
<tr>
<th>CV_ID</th>
<th>Classifier</th>
<th>Level</th>
</tr>
<?php foreach ($results as $row): ?>
<tr>
<td> <input type="checkbox" id="chk113" name="CV_ID" value="<?php echo $row->CV_ID ?> "/>
<label for="chk113"><?php echo $row->CV_ID ?> </label> </td>
<td> <input type="checkbox" id="chk111" name="Classifier" value="<?php echo $row->Classifier ?>"/>
<label for="chk111"><?php echo $row->Classifier ?></label> </td>
<td> <input type="checkbox" id="chk112" name="Value" value="<?php echo $row->Value ?>"/>
<label for="chk112"><?php echo $row->Value ?></label> </td>
</tr>
<?php endforeach ?>
</table>
<p><input id="submit" name="submit" type="submit" value="Submit Names" /></p>
</form>
保存 ?>
<?
if((isset($_POST['CV_ID'])) || (isset($_POST['Classifier'])) || (isset($_POST['Value']))) {
//first name or last name set, continue-->
$CV_ID = $_POST['CV_ID'];
$Classifier= $_POST['Classifier'];
$Value= $_POST['Value'];
$db =& JFactory::getDBO();
$query = "INSERT INTO SessionTa (CV_ID, Classifier, Value) VALUES ('".$CV_ID."','".$Classifier."','".$Value."');";
$db->setQuery($query);
$db->query();
} else {
}
?>
在我的表中出現「數組」我只是試圖插入多個行到我的數據庫表 – user3403327