the-botman Posted September 15, 2012 Share Posted September 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/ Share on other sites More sharing options...
the-botman Posted September 15, 2012 Author Share Posted September 15, 2012 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1378167 Share on other sites More sharing options...
Christian F. Posted September 15, 2012 Share Posted September 15, 2012 Indent your code properly, and it'll be a lot easier to work with it. Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1378177 Share on other sites More sharing options...
the-botman Posted September 24, 2012 Author Share Posted September 24, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1380544 Share on other sites More sharing options...
the-botman Posted September 24, 2012 Author Share Posted September 24, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1380557 Share on other sites More sharing options...
Jessica Posted September 24, 2012 Share Posted September 24, 2012 You need to check if the variable exists before using it. isset Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1380561 Share on other sites More sharing options...
the-botman Posted September 24, 2012 Author Share Posted September 24, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1380562 Share on other sites More sharing options...
the-botman Posted September 24, 2012 Author Share Posted September 24, 2012 one last question why does it only display 1 word per line? when i show the quotes list? Quote Link to comment https://forums.phpfreaks.com/topic/268408-random-quotes-from-mysql/#findComment-1380593 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.