The code below is meant to delete the record who’s id is the one rendered on the page from the query select. I am having problems how to delete that row . So instead of id = ‘233’” get the table id and delete. Can you kindly look in this code, and suggest a solution?Thanks
<form name="form1" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<?php
/* New Code */
//if($_POST['formSubmit'] == "Submit")
if (isset($_POST['formSubmit']))
{
$courseid=$_POST['rowid'];
$db8=& JFactory::getDBO();
$db8->setQuery("DELETE FROM jos_jquarks_persontraining WHERE
id = '233'");
$db8->query();
echo $courseid;
}
$database =& JFactory::getDBO();
// Display enrollments
echo "<h1>";
echo "<span style='text-decoration: underline;'>";
echo "Courses : " ;
echo "</h1>";
echo "</b>";
echo "</br>";
echo "</br>";
$database->setQuery("SELECT jos_jquarks_persontraining.id as trainingid,training.training,
DATE_FORMAT(training.trainingDate, '%W, %M %e, %Y'),
training.trainingHour, training.course_location,
date_format(jos_jquarks_persontraining.timeStamp,'%m/%d/%Y')
FROM jos_jquarks_persontraining
INNER JOIN training ON jos_jquarks_persontraining.training_id = training.training_id
WHERE
jos_jquarks_persontraining.user_id = " .$id ) ;
if (!$database->query())
{
echo "<script> alert('".$database->getErrorMsg()."'); </script>";
}
$tableStyle = "padding: 5px;border:1px solid black";
$tdStyle = "padding:5px";
$thStyle = "padding:7px";
$row = $database->loadRowList();
if ( 0<count($row)) {
echo '<table style="', $tableStyle, '" cellpadding="7" cellspacing="7">';
echo '<tr><th style="', $thStyle, '" align=center>Id</th><th style="', $thStyle, '" align=center>Course</th><th style="', $thStyle, '" align=center>Date</th>
<th style="', $thStyle, '" align=center>Time</th>
<th style="', $thStyle, '" align=center>Location</th>
<th style="', $thStyle, '" align=center>Enrollment Date</th>
<th style="', $thStyle, '" align=center>Action</th>';
$row = $database->loadRowList();
foreach($row as $valuearray) {
echo '<tr align="center">';
foreach($valuearray as $field){
echo '<td style="', $tdStyle, '" align=center>', $field, '</td>';
} // field
echo '</tr>';
echo '<tr align="center">';
echo'<td>';
//echo '<input type="submit" name="formSubmit" value="Unenroll" />';
echo '<input type="hidden" name="rowid" value="'.$row['ID'].'" ]" />';
echo '<input type="submit" name="formSubmit" value="Unenroll" />';
echo '</td>';
echo '</tr>';
} // $valuearray
echo '</table>';
}
// if count
?>
</form>
I believe you want this: