PDA

View Full Version : نحوه آپدیت اطلاعات دیتابیس mysql در php با استفاده از checkbox



conter
سه شنبه 29 بهمن 1392, 10:31 صبح
سلام من یک پیج php دارم میخواستم اطلاعات دیتا بیس که توی یک حلقه while فراخونی میشه رو با چک کردنشون توسط checkbox اپدیت شه . کد حذف به همین روشی که نوشتم درست کار میکنه اما دستور اپدیت کار نمیکنه ولی پیغامی که اخر دستور در صورت ست شدن result_new باید چاپ بشه اجرا میشه . میخواستم ببینم کسی میتونه راهنمایی کنه ببینم مشکل کارم کجاست .

این کد صفحه php :


<form action="" method="POST" >
<table>
<tr>
<td>
<?php
$connection = mysql_connect('localhost', 'root', '');
$db = mysql_select_db('table_name', $connection);
mysql_query("SET CHARACTER SET utf8;");
mysql_query("SET SESSION collation_connection = 'utf8_persian_ci'");

if(isset($_POST['inbox']) && ($_POST['inbox'] == 'Inbox'))
{
$query = mysql_query("SELECT * FROM article WHERE status='' ", $connection);
$string = '';

if (mysql_num_rows($query)){
$_SESSION["count"]=mysql_num_rows($query);

?>

<form>
<table class='styled-table'>
<tr>
<th scope='col'>Title</th>
<th scope='col'>Firstname</th>
<th scope='col'>Lirstname</th>
<th scope='col'>Email</th>
<th scope='col'>Article Title</th>
<th scope='col'>Article File</th>
<th scope='col'>Accept</th>
<th scope='col'>Reject</th>
<th scope='col'>Editor</th>
<th scope='col'>Mark</th>

</tr>

<?php while($row = mysql_fetch_assoc($query)){ ?>


<tr>
<td><input class='styled-input' type='text' name='title[]' id='title' value= "<? echo $row['title']; ?>" ></td>
<td><input class='styled-input' type='text' name='fname[]' id='fname' value= "<? echo $row['fname']; ?>" ></td>
<td><input class='styled-input' type='text' name='lname[]' id='lname' value= "<? echo $row['lname']; ?>" ></td>
<td><input class='styled-input' type='text' name='email[]' id='email' value= "<? echo $row['email']; ?>"></td>
<td><input class='styled-input' type='text' name='mastitle[]' id='mastitle' value= "<? echo $row['mstitle']; ?>"></td>
<td><a class='styled-input' href="<? echo 'pdf/'.$row['msfile']; ?>" target="_new">download</a></td>
<td><input class='styled-input' type='radio' name='status[]' id='status' value="Accepted"></td>
<td><input class='styled-input' type='radio' name='status[]' id='status' value="Rejected"></td>
<td><input class='styled-input' type='radio' name='status[]' id='status' value="Sent to Editor"></td>
<td><input class="styled-input" type="checkbox" name="checkbox[]" id="checkbox[]" value="<? echo $row['id']; ?>" /></td>

</tr>

<?php } ?>

</table>

</form>

<?php

}else
{
$string = "Nothing Found!";
}

echo $string;
}
?>

</td>
</tr>
</table>
<input class='styled-input' type='submit' name='save' id='save' value='Save'>

</form>

<!-- submiting records -->
<?php
// Check if button name "Submit" is active, do this
if(isset($_POST['save']) && $_POST['save'] == 'Save')
{

for($i=0;$i<=$_SESSION["count"];$i++)
{
$set_id = $_REQUEST['checkbox'][$i];
$sql_new=mysql_query(" UPDATE `article` SET `status`='".$_REQUEST['status'][$i]."' WHERE `id`='$set_id' ", $connection);
$result_new=mysql_query($sql_new);

}

if(isset($result_new)){
$_SESSION["count"]="";
?>
<****** language="**********">alert('Inbox informations Submitted successfully!');</******>
<?php
echo "<meta http-equiv=\"refresh\" content=\"0;URL=admin.php\">";
}

}
?>
<!-- end of setting infromations -->

conter
سه شنبه 29 بهمن 1392, 12:42 عصر
حودم مشکل رو حل کردم برای کسانی که میخوان بدونن چجوری این قسمت کد آپریت :


<?php
// Check if button name "Submit" is active, do this
if(isset($_POST['save']) && $_POST['save'] == 'Save')
{

for($i=0;$i<=$_SESSION["count"];$i++)
{
$set_id = $_REQUEST['checkbox'][$i];

$sql_new=mysql_query(" UPDATE `article` SET `status`='{$_REQUEST['status'][$i]}' WHERE `id`='$set_id' ", $connection);


}


if(isset($sql_new)){
$_SESSION["count"]="";
?>
<script language="javascript">alert('Inbox informations Submitted successfully!');</script>
<?php
echo "<meta http-equiv=\"refresh\" content=\"0;URL=admin.php\">";
}

}
?>