PHP getting an automated sql data to be deleted
I've been asked to create a Timesheet based on PHP and mySQL.
I've created a page to insert the data and another page to show the data
and edit/delete the data shown.
Here is the page to show the data and edit/delete them:
<?php
require_once("config/config.php");
$data = mysql_query("SELECT * FROM jobs")
or die(mysql_error());
?>
<form method="post" action="admin_job_edit.php" id="admin_job_edit"
name="admin_job_edit">
<table>
<?php
while($info = mysql_fetch_array( $data )) {
?>
<tr>
<td> <input type="checkbox" name="job[]" id="<?php echo
$info['job_code']?>" value="<?php echo $info['job_code']?>"
/></td>
<td><?php echo $info['job_code'] ?></td>
<td><?php echo $info['job_desc'] ?> </td>
<td><?php echo $info['job_client'] ?> </td>
<td><?php echo $info['job_year'] ?> </td>
<td><?php echo $info['job_month']?> </td>
<td><?php echo $info['job_date']?> </td>
<td><?php echo $info['job_category']?> </td>
<td>EDIT</td>
<td>DELETE</td>
</tr>
<?php } ?>
</table>
<input type="submit" name="a_delete_job" value="Delete Job" />
and here's the deleting process
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$admin_data_query = mysql_query("SELECT * FROM jobs")or
die(mysql_error());
$job_code_query = $_POST['job[]'];
while ($admin_data = mysql_fetch_array($admin_data_query)) {
if (isset($_POST['job_code'])) {
$admin_sql ="DELETE FROM jobs WHERE job_code =
'$job_code_query'";
$admin_query = mysql_query($admin_sql) or die(mysql_error());
$this->messages[] = "Job deleted.";
} else {
$this->messages[] = "Failed to delete job.";
}
}
When I tried this on my machine, it gave me
Notice: Undefined index: job[] in
C:\xampp\htdocs\seclog\classes\JobModification.php on line 29
From my understanding, the variable of job[] in the 2nd page didn't catch
the user submitted checkbox in page 1, or the first page didn't send the
data because the checkbox value(maybe i wrote it wrong)
Is there anyway around this? Thank you for anyone who has read/try to help.
No comments:
Post a Comment