/    Sign up×
Community /Pin to ProfileBookmark

Delete multiple entries – Help plxxxx

Hi, I have been trying to create a functionality which allows users to delete multiple entries from database, I have been working on this for a while now but cant get my head around it, can u please tell me what im doing wrong here?

thanks in advance

[code=php]<?php

session_start();

include (“../global.php”);
//welcome messaage
$username=$_SESSION[‘username’];
echo “$username”;

$query=mysql_query(“SELECT id FROM users WHERE username=’$username'”);
while($row = mysql_fetch_assoc($query))
{
$user_id = $row[‘id’];
echo $id;
}

$per_page=5;

$start=$_GET[‘start’];

$record_count =mysql_num_rows(mysql_query(“SELECT * FROM rent”));
?>
<td><form name=”form1″ method=”post” action=””> </td>
<?php
$max_page=$record_count/$per_page;

if(!$start)
$start=0;
$result= mysql_query(“SELECT id, msg, title, reference FROM msg LIMIT $start, $per_page”);
while($row = mysql_fetch_array($result))
{

$id=$row[‘id’];
$msg=$row[‘msg’];
$reference=$row[‘reference’];
$title=$row[‘title’];

?>

<table>

<tr>
<td align=”center” bgcolor=”#FFFFFF”><input name=”checkbox[]” type=”checkbox” id=”checkbox[]” value=”<? echo $rows[‘id’]; ?>”></td>
<td><?php echo $title; ?></td>
<td><?php echo $id; ?></td>
<td><?php echo $reference; ?></td>
<td><?php echo $msg; ?></td>

</tr>

</table>
<tr>
<td colspan=”5″ align=”center” bgcolor=”#FFFFFF”><input name=”delete” type=”submit” id=”delete” value=”Delete”></td>
</tr>
<?php

//while
}

$prev=$start – $per_page;
$next=$start + $per_page;

if(!($start<=0))
echo “<a href=’view-data.php?start=$prev’>Previous</a>”;

if(!($start>=$record_count-$per_page))
echo “<a href=’view-data.php?start=$next’>Next</a>”;
if(isset($_POST[‘delete’]))
{
for($i = 0; $i <= count($_POST[‘checkbox’]); $i++)
{
$del_id = $checkbox[$i];
$sql = “DELETE FROM rent WHERE id=’$del_id'”;
$result = mysql_query($sql);
}

if($result)
{
header(‘Location: view-data.php’);
}
}
?>

</table>
</form>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @princeofpersia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...