guestbook help

Started on the old forum in September 2012 · view the original in the archive · old links redirect here

2 replies · 1,727 views · started 14 years ago · 1 min read

3 participants
zain Junior · 43 posts #1

heya everyone...

its been ages since i have played around with codes anyways i really need some help, i have a cpanel for my wapsite which has an option to remove extries from the guestbook, now my issue is this i can only remove one extry at a time and sometimes that takes forever LOL, anyways i want to beable to tick each one i want to remove then click remove, here is the code i am using right now.

<?php
	include 'GbManager_Header.php'; 
	$Action = Get_QString('Action'); //Requests Postback status from the Querystring.
	$Id = Get_QString('Id');

	if ($Action == "Remove") {
		Show_List(Remove_Message($Id));
	} else {
		Show_List("False");	
	}

	include 'GbManager_Footer.php';

function Remove_Message($Id) {
	$Result = "False";
	$DbRes = MySqlCmd("DELETE From page_guestbook WHERE Gbk_Id='$Id'");
	if ($DbRes != "1") {
		$Result = "Database Error.";
	}
	return $Result;
}
function Show_List($ShowError) {
	$SqlResult = MySqlSelect("Select * From page_guestbook ORDER BY Gbk_Date,Gbk_Time,Gbk_Name");
	$RowCnt = mysql_numrows($SqlResult);
		
	$Spacing = "					";
	echo $Spacing.'<center>'."\n";
	echo $Spacing.'<br>'."\n";
	echo $Spacing.'<table border="0" cellpadding="0" cellspacing="0" style="color: #666;font-size:11px;width:550px;">'."\n";
	echo $Spacing.'	<tr height="15" align="left"><td><span class="Form_Title">Guestbook Messages</span><HR width="100%" SIZE="1"></td></tr>'."\n";
	echo $Spacing.'</table>'."\n";

	echo $Spacing.'<br>'."\n";
	echo $Spacing.'<table border="0" cellpadding="0" cellspacing="1" style="font-size:9pt;width:550px;">'."\n";
	echo $Spacing.'	<tr style="background-color:#666;color:#FFF;"><td style="background-color:#FFF;color:#FFF;"></td><td><b>  Date</b></td><td><b>  Time</b></td><td><b>  Message</b></td><td align="center"><b>Action</b></td></tr>'."\n";

	if ($RowCnt > 0) {
	$i = 0;
	while ($i < $RowCnt) {
		$Gbk_Id = mysql_result($SqlResult,$i,"Gbk_Id");
		$Gbk_Date = mysql_result($SqlResult,$i,"Gbk_Date");
		$Gbk_Time = mysql_result($SqlResult,$i,"Gbk_Time");
		$Gbk_Name = mysql_result($SqlResult,$i,"Gbk_Name");
		$Gbk_Message = mysql_result($SqlResult,$i,"Gbk_Message");

		$Remove_Link = "Guestbook.php?Action=Remove&Id=$Gbk_Id";

		$Spacing = "						";

		echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">';
		echo '<td style="background-color:#FFF;"></td>';

		echo '<td style="width:80px;">  '.$Gbk_Date.'</td>';
		echo '<td style="width:60px;">  '.$Gbk_Time.'</td>';
		echo '<td>  <b>'.$Gbk_Name.'</b><br>  '.$Gbk_Message.'</td>';

		echo '<td align="center" style="width:50px;">';
		echo '<table border="0" cellpadding="0" cellspacing="0" style="margin-top:2px;width:38px;height:16px;">';
			echo '<tr height="16" align="center"><td>';
				echo '<a href="#" onclick="return hs.htmlExpand(this, { headingText: '."'Delete Message'".' })"><img src="Design/Images/Remove.png" title="Remove"></a>';
				echo '<div class="highslide-maincontent">';
					echo "Are you sure that you want to remove this message? <br><br>";
					echo '<a href="'.$Remove_Link.'">Yes</a>';
					echo '<b> | </b>';
					echo '<a href="#" title="{hs.lang.closeTitle}" onclick="return hs.close(this)">No</a>';
				echo "</div>";
			echo '</td></tr>';
			echo '<tr><td></td></tr>';
		echo '</table>';
		echo '</td>';

		echo "</tr>\n";		

		$i++;
	}
	} else {
		$Spacing = "						"; 
		echo $Spacing.'<tr><td></td><td><font face="Verdana" size="2"><b>No Entries Found.</b></font><br></td></tr>'."\n"; 
	}
	$Spacing = "					"; 
	echo $Spacing."</table><br><br></center>\n";
}

?>
tkreturns Developer · 98 posts #2

Here you go!

<?php
$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="test_mysql"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
</tr>

<?php
}
?>

<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>

<?php

// Check if delete button active, start this 
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php 
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
}
}
mysql_close();
?>

</table>
</form>
</td>
</tr>
</table>

Found it on my pc. Just change the sql. Cheers ✌️😮

ASK FOR HELP

arnage Lead · 811 posts #3

Maybe... 🙂 With <form> and check boxes with id of entry within

while ($i < $RowCnt) ...

and create an array, than just do loop and delete it.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close