私は自分の問題を解決することに非常に近づいています。これが私がいるところです:
while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
{
echo '<tr><td align="left">' .
$row['title'] . '</td><td align="left">'
. $row['genre'] . '</td><td align="left">'
. $row['length'] . '</td><td align="left">'
. $row['created'] . '</td><td align="left">'
. $row['views'] . '</td><td align="left">' //. var_dump($row) //dump row value for testing
. '<input type="checkbox" name="checkbox[]" value= "'.$row['upload_id'].'"'.' />'.' </td>'. '</tr>';
}
echo '</table>'; // Close the table
および削除機能:
function submit_delete() {
if(!is_null($_POST['delete']) && !is_null($_POST['checkbox'])) { //Check to see if a delete command has been submitted.
//This will dump your checkbox array to your screen if the submit works.
//You can manually check to see if you're getting the correct array with values
var_dump($_POST['checkbox']);//Comment this out once it's working.
deleteUploads($id_array);
}
else {
echo "Error: submit_delete called without valid checkbox delete.";var_dump($_POST['checkbox']);
}
}
function deleteUploads ($id_array) {
if (count($id_array) <= 0) { echo "Error: No deletes in id_array!"; var_dump($_POST['checkbox']); return; }//bail if its empty
$delete_success = false;
foreach ($id_array as &$id) {
$sql = "DELETE FROM `upload` WHERE `upload_id`=$id AND `owner_id`={$_SESSION['user_id']}";
$result = $mysqli->query($sql) or die(mysqli_error($mysqli));
if ($result) { $delete_success = true; }
}
if($delete_success) {
header('Location: newwriter_profile.php');
} else {
echo "Error: ".mysqli_error();
}
}
//Test deleteUploads (remove once you know the function is working)
//$test_ids = array();
//$test_ids[] = 5;//make sure this id is in the db
//$test_ids[] = 7;//this one too
submit_delete();
//deleteUploads($id_array);//should remove ids 10 and 9//
mysqli_close($dbc);
id_array
チェックボックスの正しい$_POST
値を取得していないと判断しました。vardump は正しいアップロード ID を持っていることを示し、次に vardump を実行id_array
すると NULL が表示されます。どんな助けでも大歓迎です。
現在:
function submit_delete() {
if(!is_null($_POST['delete']) && !is_null($_POST['checkbox'])) { //Check to see if a delete command has been submitted.
//This will dump your checkbox array to your screen if the submit works.
//You can manually check to see if you're getting the correct array with values
// var_dump($_POST['checkbox']);//Comment this out once it's working.
$id_array = $_POST['checkbox'];
var_dump($id_array);
deleteUploads($id_array);
}
else {
echo "Error: submit_delete called without valid checkbox delete.";//var_dump($_POST['checkbox']);
}
}
function deleteUploads ($id_array) {
if (count($id_array) <= 0) { echo "Error: No deletes in id_array!"; return; }//bail if its empty
$delete_success = false;
foreach ($id_array as $id) {
$sql = "DELETE FROM `upload` WHERE `upload_id`=$id AND `owner_id`={$_SESSION['user_id']}";
$result = $mysqli->query($sql) or die(mysqli_error($mysqli));
if ($result) { $delete_success = true; }
}
if($delete_success) {
header('Location: newwriter_profile.php');
} else {
echo "Error: ".mysqli_error();
}
}
id_array=POST の後に正しい vardump を取得していますが、delete を送信した後、viewsource は、私の末尾の後に何も読み取られていないことを示しています (サイドバーとフッターが消えます)。現在報告されているエラーはありません。