نوشته شده توسط
funpatogh
مشکل شما توی فرم هست و چون
اینکار را هم کردم نشد.
این مشکل را توی یکی از این فرومهای خارجی مطرح کردم و اونها همچین جوابی بهم دادن:
There are a couple issues here:
- The meta tag will not work outside the head element on an HTML document, so that method is out.
- Your loop will only validate if the last delete statement worked, not all of them
- You can use the header instruction instead, but you'll need to reorder the code to accomplish what you want.
- A non-php word of advice - avoid inline styles as much as possible. You'll save yourself a lot of headaches. You can use multiple classes for the same element, just separating them by a space...
- The generated page will not validate because you've got form elements (the checkboxes) outside the form itself, so results can get sketchy....
This should get you what you need. If not, ensure that your ID is actually a character field - if not, remove the quotes around $del_id in the delete statement.
بعد همچین کدی دادن:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel=stylesheet type=text/css href="style.css"> <title>Untitled Document</title>
<style type="text/css">
.bigandbold { font-size: 20px; font-weight: bold; }
.error { color: red; font-weight: bold; }
</style>
</head>
<body>
<?php include('config.php');
// First delete the records necessary
$errDesc = "";
if(isset($_POST['delete'])) {
$checkbox = $_POST['checkbox'];
for($i=0;$i<$count;$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM test_mysql WHERE id='$del_id'";
$result = mysql_query($sql);
if (!$result) { $errDesc .= "<p>Error deleting $del_id";
}
}
// if successful redirect to delete_multiple.php
// NOTE: If **this** page is delete_multiple.php, then this whole if statement is not needed..
if (strLen($errDesc) == 0) {
header("Location: delete.php");
}
}
$result = mysql_query("SELECT * FROM test_mysql ORDER BY name ASC");
$count=mysql_num_rows($result);
?>
<div class="container">
<div class="header"> Header </div>
<div class="nav4 bigandbold">1</div>
<div class="nav4 bigandbold">#</div>
<div class="content bigandbold">Name</div>
<div class="nav3 bigandbold">LastName</div>
<div class="sidebar bigandbold">Email</div>
<?php
if(strLen($errDesc) > 0){
echo '<div class="error">'. $errDesc .'</div>';
}
$count=count($checkbox);
while($row = mysql_fetch_array($result)) {
echo '<div class="chekbox"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$rows[id].'"></div>';
echo '<div class="nav4">'. $row['id'] .'</div>';
echo '<div class="content"><a href="update.php?id='.$row['id'].'">'.$row['name'].'</a></div>';
echo '<div class="nav3">' . $row['lastname'] . '</div>';
echo '<div class="sidebar">' . $row['email'] . '</div>';
}
?>
<div class="delete">
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<input name="delete" type="submit" id="delete" value="">
</form>
</div>
<div class="footer">Footer</div>
</div>
</body>
</html>
فقط این کد یک ارور داره اونم اینه که بعد از کلیک روی دکمه حذف صحفه رفرش میشه و همچین اروری تو همون صفه میاد:
Warning: Cannot modify header information - headers already sent by (output started at /home/zigsmhos/public_html/test/idu/display.php:6) in /home/zigsmhos/public_html/test/idu/display.php on line 27
با Notepad تبدیل به UTF-8 کردم بازم نرفت.تو php.ini تظيم output_buffering را on کردم، نرفت.ob_start(); را گذاشتم، نرفت که نرف.
حالا شما بگید چیکارش کنم؟