Jump to content

guestbook code help


the-botman

Recommended Posts

hey guys...

 

its been ages since i messed with coding anyways this is what i needed this code to do, i have a guestbook and could only remove 1 post at a time with my old code, so i am trying to make a checkbox with a delete button bellow it to remove multipul rows with one click but i just can`t figure out what i am doing wrong, i will post  the old code and the new one and i got one to work but it is not a clean way of doing this.

 

old code

<?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";
}


?>

working code

<?php
include 'GbManager_Header.php'; 
$host="localhost"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="name"; // Database name 
$tbl_name="page_guestbook"; // 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);

include 'GbManager_Footer.php';


?>
<center>
<table width="400" border="0" cellspacing="1" cellpadding="0"> 
    <tr> 
        <td> 
            <form name="form1" method="post" action=""> 
            <table width="500" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
            
            <tr> 
                <td align="center" bgcolor="#FFFFFF">Tick to Remove</td> 
                <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> 
                <td align="center" bgcolor="#FFFFFF"><strong>Time</strong></td> 
                <td align="center" bgcolor="#FFFFFF"><strong>Date</strong></td> 
                <td align="center" bgcolor="#FFFFFF"><strong>Message</strong></td> 
            </tr> 
            <?php while ($rows = mysql_fetch_array($result)): ?> 
            <tr> 
                <td align="center" bgcolor="#FFFFFF"><input name="need_delete[<? echo $rows['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td> 
                <td bgcolor="#FFFFFF"><? echo $rows['Gbk_Name']; ?></td> 
                <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['Gbk_Time']); ?></td> 
                <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['Gbk_Date']); ?></td> 
                <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['Gbk_Message']); ?></td> 
            </tr> 
            <?php endwhile; ?> 
            <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(isset($_POST['need_delete'])) {

  $i = 0; 
  while(list($key, $val) = each($_POST['need_delete'])) { 
    $sql = "DELETE FROM $tbl_name WHERE Gbk_Id='$val'"; 
    mysql_query($sql); 
    $i += mysql_affected_rows(); 
  } 

  // if successful redirect to Guestbook.php 
  if($i > 0){ 
    echo '<meta http-equiv="refresh" content="0;URL=Guestbook.php">'; 
  } 
} 

                mysql_close(); 
            ?> 
            </table> 
            </form> 
        </td> 
    </tr> 
</table> 
</center>






and this is the code i am busy with but just can`t get right it comes from the first code

<?php
include 'GbManager_Header.php'; 
$Id = Get_QString('Id');

if(isset($_POST['need_delete'])) {
  $i = 0; 
   while(list($key, $val) = each($_POST['need_delete']))
	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='$val'");
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.'<form name="form1" method="post" action="">'."\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");


	$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;">';
	?>
	<td align="center" bgcolor="#FFFFFF"><input name="need_delete[<? echo $rows['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td> 
	</tr> 
             <tr> 
                <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> 
            </tr>

	<?php
			echo "</div>";
		echo '</td></tr>';
		echo '<tr><td></td></tr>';

	echo '</table>';
	echo '</form> ';
	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";
}


?>

 

thanks in advance

Zainul

Link to comment
Share on other sites

this is where i am now please tell me what i am doing wrong, it shows the check box with a delete button under each box which is wrong that should be at the bottom and it wont delete

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

      while(list($key, $Id) = each($_POST['need_delete'])) {
  $Id = Get_QString('Id');
  }
 if(isset($_POST['need_delete'])) {
	 Show_List(Remove_Message($Id));
 } else {
	 Show_List("False");	
 }

 include 'GbManager_Footer.php';

function Remove_Message($Id) {
  $SqlResult = MySqlSelect("Select * From page_guestbook ORDER BY Gbk_Date,Gbk_Time,Gbk_Name");
  $RowCnt = mysql_numrows($SqlResult);
		  	 $Result = "False";
  $i = 0; 
  $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.'<form name="form1" method="post" action="">'."\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;">';
	 ?>		
	 <input name="need_delete[<? echo $rows['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td>
	            <tr> 
                <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> 
            </tr> 
	<?php
			 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";
}


?>

Link to comment
Share on other sites

i am sorry i keep posting here but i want to show you guys i am really trying anyways i got the checkbox in order and the delete button at the bottom i am not sure why but when i tick and click 1 and delete it does not delete and if i click 3 rows it does not delete it just displays 4 tables gosh i must sound silly i know its now something small but i just can`t figure this one out
here is the code
[code<?php
 include 'GbManager_Header.php'; 
	$SqlResult = MySqlSelect("Select * From page_guestbook ORDER BY Gbk_Date,Gbk_Time,Gbk_Name");
	  
 if(isset($_POST['need_delete'])) {
 	while(list($key, $val) = each($_POST['need_delete'])) {
	$Id = $val;
	 Show_List(Remove_Message($Id));
 } 
 }else {
	 Show_List("False");	
 }

 include 'GbManager_Footer.php';

function Remove_Message($Id) {
	$SqlResult = MySqlSelect("Select * From page_guestbook ORDER BY Gbk_Date,Gbk_Time,Gbk_Name");
	$RowCnt = mysql_numrows($SqlResult);

$Result = "False";
	$i = 0; 
	$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.'<form name="form1" method="post" action="">'."\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");


	 $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;">';
	 ?>
	 <input name="need_delete[<? echo $RowCnt['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $RowCnt['Gbk_Id']; ?>]" value="<? echo $RowCnt['Gbk_Id']; ?>"></td>
<?php

			 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";
 	 echo '<input name="delete" type="submit" id="delete" value="Delete"></center>';
	  echo '</form>';
}

?>

Link to comment
Share on other sites

hey ok see this is where i am now everything seems fine to me but it just wont delete i have tried everything i just dont get why its not deleting here is my code and thanks alot for your help

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


 if(isset($_POST['need_delete'])) {
 $Id = $_POST['need_delete'];
	 Show_List(Remove_Message($Id));
 } else {
	 Show_List("False");	
 }
 include 'GbManager_Footer.php';

function Remove_Message($Id) {
 $Result = "False";
  $i = 0; 
  while(list($key, $val) = $Id) { 
   	 $SqlResult = MySqlSelect("DELETE FROM page_guestbook WHERE Gbk_Id='$val'");  
 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:450px;">'."\n";
		 echo $Spacing.'<tr>'."\n";
	 echo $Spacing.'<td>'."\n";
    		 echo $Spacing.'<form name="form1" method="post" action="Guestbook.php?Action=Remove">'."\n";   
	 echo $Spacing.'<tr style="background-color:#666;color:#FFF;"><td style="background-color:#FFF;color:#FFF;"></td>'."\n"; 
	 echo '<td><b>Delete</b></td>'."\n"; 
	 echo '<td><b>  Date</b></td>'."\n"; 
	 echo '<td><b>  Time</b></td>'."\n"; 
     echo '<td align="center"><b>Message</b></td>'."\n";
	 echo '<td align="center"><b>Action</b></td>'."\n";
	 echo '</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");

	while ($rows = mysql_fetch_array($SqlResult));
	$Spacing = "						 ";

	 echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">';
	 echo '<td></td>';
	 ?>
         <td><input name="need_delete[<? echo $rows['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td>
	 <?php
	 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><input name="delete" type="submit" id="delete" value="" class="Form_Btn_delete"></td>'."\n";  
         echo '</table>'."\n"; 
         echo '</form>'."\n"; 

         echo '</td>'."\n"; 
         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";
}	
?>

Link to comment
Share on other sites

when i use the code like this and try and delete just 1 message

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


 if(isset($_POST['need_delete'])) {
 $Id = $_POST['need_delete'];
	 Show_List(Remove_Message($Id));
 } else {
	 Show_List("False");	
 }
 include 'GbManager_Footer.php';

function Remove_Message($Id) {
 $Result = "False";
 $ids_to_delete = array_filter(array_map('intval', $_POST['needs_delete']));   // clean up the post data
$SqlResult = "DELETE FROM page_guestbook WHERE id IN (" . join(',', $ids_to_delete) . ")";  
 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:450px;">'."\n";
		 echo $Spacing.'<tr>'."\n";
	 echo $Spacing.'<td>'."\n";
    		 echo $Spacing.'<form name="form1" method="post" action="Guestbook.php?Action=Remove">'."\n";   
	 echo $Spacing.'<tr style="background-color:#666;color:#FFF;"><td style="background-color:#FFF;color:#FFF;"></td>'."\n"; 
	 echo '<td><b>Delete</b></td>'."\n"; 
	 echo '<td><b>  Date</b></td>'."\n"; 
	 echo '<td><b>  Time</b></td>'."\n"; 
     echo '<td align="center"><b>Message</b></td>'."\n";
	 echo '<td align="center"><b>Action</b></td>'."\n";
	 echo '</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");

	while ($rows = mysql_fetch_array($SqlResult));
	$Spacing = "						 ";

	 echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">';
	 echo '<td></td>';
	 ?>
         <td><input name="need_delete[<? echo $rows['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td>
	 <?php
	 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><input name="delete" type="submit" id="delete" value="" class="Form_Btn_delete"></td>'."\n";  
         echo '</table>'."\n"; 
         echo '</form>'."\n"; 

         echo '</td>'."\n"; 
         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";
}	
?>

i get this error message

Notice: Undefined index: needs_delete in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 16 Warning: array_map() [0function.array-map0]: Argument #2 should be an array in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 16 Warning: array_filter() expects parameter 1 to be array, null given in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 16 Warning: join() [0function.join0]: Invalid arguments passed in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 17

Link to comment
Share on other sites

i think thats what i did? this is where i placed the echo statment even if i place it above the first if statment i get the same outcome

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


 if(isset($_POST['need_delete'])) {
 	 echo '<b>'.$_POST['need_delete'].'</b>';
 $Id = $_POST['need_delete'];
	 Show_List(Remove_Message($Id));
 } else {
	 Show_List("False");	
 }
 include 'GbManager_Footer.php';

Link to comment
Share on other sites

errr a sql query is a question or a request? like erm.. with mysql u query a database for information

i will try and be as honest as i can be i am a back door coder LOL i learn from trial and error and i have made some really good scripts that way which i host on www.bhawap.com but this dam guestbook really got the better of me i have tried searching google and i have tried reading i just can`t figure this out hence why i turned to php freaks i am a do it myself kinda guy but this dam script makes me feel like pulling my hair out lol i have a working version its just i am not happy with the way it was coded as you see in my "working version" anyways thanks alot for your time
Link to comment
Share on other sites

If you don't understand basic debugging, I can assure you that your other scripts are not "Really good". If you want to become a good programmer, you need to learn to debug your code. Which includes paying attention when people try to help, and thinking about what you're doing, not just randomly typing things and calling it good when it doesn't blow up.

Link to comment
Share on other sites

i can`t give up LOL now this is the code i have now

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

  if(isset($_POST['need_delete'])) {
  		 print_r ($_POST['need_delete']);
	$ids_to_delete = array_filter(array_map('intval', $_POST['need_delete']));   // clean up the post data
	  Show_List(Remove_Message($ids_to_delete));
  } else {
	  Show_List("False");	
  }
  include 'GbManager_Footer.php';

function Remove_Message($ids_to_delete) {
  $Result = "False";
 $SqlResult = "DELETE FROM page_guestbook WHERE id IN (" . join(',', $ids_to_delete) . ")";  
  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:450px;">'."\n";
		  echo $Spacing.'<tr>'."\n";
	  echo $Spacing.'<td>'."\n";
    		  echo $Spacing.'<form name="form1" method="post" action="Guestbook.php?Action=Remove">'."\n";   
	  echo $Spacing.'<tr style="background-color:#666;color:#FFF;"><td style="background-color:#FFF;color:#FFF;"></td>'."\n"; 
	  echo '<td><b>Delete</b></td>'."\n"; 
	  echo '<td><b>  Date</b></td>'."\n"; 
	  echo '<td><b>  Time</b></td>'."\n"; 
      echo '<td align="center"><b>Message</b></td>'."\n";
	  echo '<td align="center"><b>Action</b></td>'."\n";
	  echo '</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");

	 $Spacing = "						  ";

	  echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">';
	  echo '<td></td>';
	  
         echo '<td><input name="need_delete" type="checkbox" id="checkbox'.$Gbk_Id.'" value="'.$Gbk_Id.'"></td>'."\n";

	  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><input name="delete" type="submit" id="delete" value="" class="Form_Btn_delete"></td>'."\n";  
         echo '</table>'."\n"; 
         echo '</form>'."\n"; 

         echo '</td>'."\n"; 
         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";
}	
?>

and this is what it prints with the error msg

2012090610222150486b4d9c8b9625459298 Warning: array_map() [0function.array-map0]: Argument #2 should be an array in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 8 Warning: array_filter() expects parameter 1 to be array, null given in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 8 Warning: join() [0function.join0]: Invalid arguments passed in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Guestbook_Manager/Show_List.php on line 17

 

now this shows that its getting the message Id but its not deleting

Link to comment
Share on other sites

i changed the checkbox code and it now gives me this with the print Array ( [0] => )

the code i changed it to is

	   while ($rows = mysql_fetch_array($SqlResult)); 

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

         <?php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.