Jump to content

Recommended Posts

heya everyone...

i need some help.. ok what i have is a random quotes script, i have a section in my cpanel where i have the option to add, view or remove multiple entries, now the issue is the entries and the remove form show together i am not sure what i am doing wrong , then it seems when i add 1 entry i can`t add a a 2nd but i can remove multiple rows fine here is my code

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

 if ($Action == "Remove") {
	 Remove_Quote();
}
 if ($Action == "Add") {
 Add_Now();
 } else
	 Show_Add_form();	
		 if ($Action != "Remove") { 
	Show_Quotes();
}
 include 'Random-Quotes_Footer.php';

function Remove_Quote() {
 $Result = "False";
 while(list($key, $val) = each($_POST['need_delete'])) {
 $DbRes = MySqlCmd("DELETE FROM GET_QUOTES WHERE REC_QUOTES_ID='$val'");
 }
 if ($DbRes != "1") {
	 $Result = "Database Error.";
 }
 return $Result;
}
function Add_Now() {
$Quote = $_POST['Quote'];
echo '	<div class="hd2"><center><font color=FFD700><strong>Guestbook</strong></font></center></div><br>'."\n";
	if ($Quote != "") {
		$Entry_ID = GetGuid();
 		$DbRes = MySqlCmd("INSERT INTO GET_QUOTES VALUES ('$Entry_ID','$Quote')");
		if ($DbRes != "1") {
			echo '<font face="Verdana" color="#FF0000" size="2">Database error, please try again.</font><br>'."\n";
		} else {
			echo '<font face="Verdana" size="2">Your entry has been saved. <img src="../Images/Smileys/icon_cool.gif" border="0" alt="" /></font><br>'."\n";
		}
	} else {
		echo '<font face="Verdana" color="#FF0000" size="2"><u>Quote</u> cannot be left blank.</font><br>'."\n";
	}
}

function Show_Add_form() {
echo '	<div class="hd2"><center><font color=#FFD700><strong>Add Quote</strong></font></center></div><br>'."\n";
echo '<center>'."\n";
echo '<form method="post" action="Random-Quotes_Manager.php?Action=Add">'."\n";
echo '	<table border="0" cellpadding="0" cellspacing="0" style="font-size:9pt;width:100px;">'."\n";
echo '		<tr><td align=left>Quote:</td></tr>'."\n";
echo '		<tr><td><textarea name="Quote"></textarea></td></tr>'."\n";
echo '		<tr><td colspan="2" align=center><br><input type="submit" value="Quote!" name="Submit"></td></tr>'."\n";
echo '	</table>'."\n";
echo '</form>'."\n";
echo '</center>'."\n";
}
function Show_Quotes() {
 $SqlResult = MySqlSelect("Select * From GET_QUOTES ORDER BY REC_QUOTES_ID,REC_QUOTES");
 $RowCnt = mysql_numrows($SqlResult);

	 if ($RowCnt > 0) {	
 $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">Random Quotes</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>  Random Quote Id</b></td><td><b>  Random Quotes</b></td><td><b>  Delete</b></td></tr>'."\n";


 $i = 0;
 while ($i < $RowCnt) {
	 $REC_QUOTES_ID = mysql_result($SqlResult,$i,"REC_QUOTES_ID");
	 $REC_QUOTES = mysql_result($SqlResult,$i,"REC_QUOTES");
     $Spacing = "						 ";

 echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">';
 echo '<td style="background-color:#FFF;"></td>';
 echo '<td style="width:20px;">  '.$REC_QUOTES_ID.'</td>';
 echo '<td style="width:60px;">  '.$REC_QUOTES.'</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 '<form name="form1" method="post" action="Random-Quotes_Manager.php?Action=Remove&Post=True">';
 echo '<tr height="16" align="center"><td>';
 echo '<td align="center"><input name="need_delete['.$REC_QUOTES_ID.']" type="checkbox" id="checkbox['.$REC_QUOTES_ID.']" value="'.$REC_QUOTES_ID.'"></td>';
 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";
 if ($RowCnt > 0) {
 echo '<tr>'; 
 echo '<td align="center" style="width:50px;">';
     echo '<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" color="#666666" type="submit" id="delete" value="" class="Form_Btn_delete" /></td></td>'; 
     echo '</tr>';
 echo '</form>';
}
}

?>

Thanks in Advance

Zainul

Link to comment
https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/
Share on other sites

i know the reason it is showing both the add quote and the quotes together is because of this part of the code but i dont know any other way

if ($Action == "Remove") {
	  Remove_Quote();
}
  if ($Action == "Add") {
  Add_Now();
  } else
	  Show_Add_form();	
		  if ($Action != "Remove") { 
	 Show_Quotes();
}

  • 2 weeks later...

i just dont get why its still doing the same thing, iv`e tried a new angle but same results ... here is my code

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

if (($Action == "Remove") && ($Post = "True")) {
  Remove_Quote();
}
if($_GET['Finish'] == "True") {
 $Quote = $_POST['Quote'];
 Add_Now($Quote);
} elseif ($Action == "Add") {
  Show_Add_form();
}   else
 Show_Quotes();
 include 'Random-Quotes_Footer.php';
function Remove_Quote() {
 $Result = "False";
 while(list($key, $val) = each($_POST['need_delete'])) {
 $DbRes = MySqlCmd("DELETE FROM GET_QUOTES WHERE REC_QUOTES_ID='$val'");
 }
 if ($DbRes != "1") {
  $Result = "Database Error.";
 }
 return $Result;
}
function Add_Now($Quote) {
echo ' <div class="hd2"><center><font color=FFD700><strong>Random Quotes</strong></font></center></div><br>'."\n";
 if ($Quote != "") {
  $Entry_ID = GetGuid();
   $DbRes = MySqlCmd("INSERT INTO GET_QUOTES VALUES ('$Entry_ID','$Quote')");
  if ($DbRes != "1") {
   echo '<font face="Verdana" color="#FF0000" size="2">Database error, please try again.</font><br>'."\n";
  } else {
   echo '<font face="Verdana" size="2">Your entry has been saved. <img src="../Images/Smileys/icon_cool.gif" border="0" alt="" /></font><br>'."\n";
  }
 } else {
  echo '<font face="Verdana" color="#FF0000" size="2"><u>Quote</u> cannot be left blank.</font><br>'."\n";
 }
}
function Show_Add_form() {
echo ' <div class="hd2"><center><font color=#FFD700><strong>Add Quote</strong></font></center></div><br>'."\n";
echo '<center>'."\n";
echo '<form method="post" action="Random-Quotes_Manager.php?Action=Add&Finish=True">'."\n";
echo ' <table border="0" cellpadding="0" cellspacing="0" style="font-size:9pt;width:100px;">'."\n";
echo '  <tr><td align=left>Quote:</td></tr>'."\n";
echo '  <tr><td><textarea name="Quote"></textarea></td></tr>'."\n";
echo '  <tr><td colspan="2" align=center><br><input type="submit" value="Quote!" name="Submit"></td></tr>'."\n";
echo ' </table>'."\n";
echo '</form>'."\n";
echo '</center>'."\n";
}
function Show_Quotes() {
 $SqlResult = MySqlSelect("Select * From GET_QUOTES ORDER BY REC_QUOTES_ID,REC_QUOTES");
 $RowCnt = mysql_numrows($SqlResult);
  if ($RowCnt > 0) {
 $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">Random Quotes</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>  Random Quote Id</b></td><td><b>  Random Quotes</b></td><td><b>  Delete</b></td></tr>'."\n";

 $i = 0;
 while ($i < $RowCnt) {
  $REC_QUOTES_ID = mysql_result($SqlResult,$i,"REC_QUOTES_ID");
  $REC_QUOTES = mysql_result($SqlResult,$i,"REC_QUOTES");
  $Spacing = "	   ";
 echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">';
 echo '<td style="background-color:#FFF;"></td>';
 echo '<td style="width:20px;">  '.$REC_QUOTES_ID.'</td>';
 echo '<td style="width:60px;">  '.$REC_QUOTES.'</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 '<form name="form1" method="post" action="Random-Quotes_Manager.php?Action=Remove&Post=True">';
 echo '<tr height="16" align="center"><td>';
 echo '<td align="center"><input name="need_delete['.$REC_QUOTES_ID.']" type="checkbox" id="checkbox['.$REC_QUOTES_ID.']" value="'.$REC_QUOTES_ID.'"></td>';
 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";
 if ($RowCnt > 0) {
 echo '<tr>';
 echo '<td align="center" style="width:50px;">';
 echo '<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" color="#666666" type="submit" id="delete" value="" class="Form_Btn_delete" /></td></td>';
 echo '</tr>';
 echo '</form>';
}
}
?>

please help me its been almost a 2 weeks and i still can`t get this right :(

now with this code i can add as many random quotes as i want and it works 100% i can remove as many rows as i want but... i just have 1 problem when i add a quote i dont get an error but when im showing the list or removing a quote i get this error

Notice: Undefined index: Finish in /var/www/vhosts/bhawap.com/httpdocs/cPanel/Include/Random-Quotes_Manager/Show_List.php on line 7

ok silly me i found what was wrong lol i changed this part

<?php
 include 'Random-Quotes_Header.php';
 $Action = Get_QString('Action'); //Requests Postback status from the Querystring.
  $Finish = Get_QString('Finish'); //Requests Postback status from the Querystring.
 if (($Action == "Remove") && ($Post = "True")) {
  Remove_Quote();
}
if($Finish == "True") {

and all is well thanks alot guys

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.