wildteen88 Posted May 20, 2008 Share Posted May 20, 2008 Shouldn't do as I'm not using any MySQL5 functionality. Post the full error here. I did have a slight typo in the delete queries. Originally the queries where: DELETE * FROM ... rest of query ... The corrected queries are now DELETE FROM ... rest of query ... However just noticed something about your id field from the screenshot you posted. The extra column for the id row should be set to auto_increment. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-545857 Share on other sites More sharing options...
Cory94bailly Posted May 20, 2008 Author Share Posted May 20, 2008 Shouldn't do as I'm not using any MySQL5 functionality. Post the full error here. I did have a slight typo in the delete queries. Originally the queries where: DELETE * FROM ... rest of query ... The corrected queries are now DELETE FROM ... rest of query ... However just noticed something about your id field from the screenshot you posted. The extra column for the id row should be set to auto_increment. I guess I'll change it to the newest mysql And I tried adding it auto_increment and I got this: #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-545932 Share on other sites More sharing options...
wildteen88 Posted May 20, 2008 Share Posted May 20, 2008 You'll need to set the id field to a primary key too, before setting it to auto_increment. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-545963 Share on other sites More sharing options...
Cory94bailly Posted May 21, 2008 Author Share Posted May 21, 2008 You'll need to set the id field to a primary key too, before setting it to auto_increment. I fixed that.. But I still get the errors. I'll change the mysql's version tomorrow and see if that does anything. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-546248 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 Ok.. changing the mysql version did nothing. I got the same 3 errors.. Also, here's the source code of the show news page.. <table> <tr> <th>STICKY: <u>Sticky</u></th> </tr> <tr> <td>Sticky</td> </tr> <tr> <th><u>Not-Sticky</u></th> </tr> <tr> <td>Not-Sticky</td> </tr> <tr> <th><u>Nothing At All</u></th> </tr> <tr> <td>Nothing At All</td> </tr> </table><br /> That's there it shows spaces in front of the non stickies. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-546987 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 Here's the structure: Here's the actual values: Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-546993 Share on other sites More sharing options...
wildteen88 Posted May 22, 2008 Share Posted May 22, 2008 Can you post the code here along with the errors messages in full. I have tested my code for syntax errors and even set-up a temporary news table like yours, to see if the code works correctly. Which it does from my testing. You tried clearing your browsers cache? Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547427 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 News.php (User end): <?php require('includes/config.php'); // Make a MySQL Connection mysql_connect("$path", "$username", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); $query1 = "SELECT * FROM news ORDER BY id, sticky ASC"; $result1 = mysql_query($query1) or die(mysql_error()); function printNews($result) { if ( mysql_num_rows($result) < 1 ) { echo "<h1>No news!</h1>"; } else { echo "<table>\n"; while($news = mysql_fetch_assoc($result)) { $sticky = ($news['sticky'] == 'y') ? 'STICKY: ' : ''; echo <<<HTML <tr> <th>{$sticky}<u>{$news['title']}</u></th> </tr> <tr> <td>{$news['news']}</td> </tr> HTML; } echo "\n</table><br />"; } } printNews($result1); // Non-sticky News ?> News.php (Admin end): <?php require('config.php'); // Make a MySQL Connection mysql_connect("$path", "$username", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); if(isset($_POST['postnews'])) { $title = mysql_real_escape_string($_POST['title']); $news = mysql_real_escape_string($_POST['news']); //Check thate status of the sticky radio button $sticky = (isset($_POST['sticky']) && $_POST['sticky'] == 'y') ? 'y' : 'n'; //Insert the news $query = mysql_query("INSERT INTO news (title, news, sticky) VALUES ('$title', '$news', '$sticky')") or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'> News posted!"; } elseif(isset($_POST['delete'])) { //Delete all non-sticky news if(isset($_POST['delete']['r'])) { $qry = 'DELETE * FROM news WHERE sticky=\'n\''; $msg = 'All <b>non-stickied</b> news deleted!'; } //Delete all stickied news if(isset($_POST['delete']['s'])) { $qry = 'DELETE * FROM news WHERE sticky=\'y\''; $msg = 'All <b>stickied</b> news deleted!'; } //Delete all news else { $qry = 'TRUNCATE TABLE news'; $msg = 'All news deleted!'; } mysql_query($qry)or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'> $msg"; } else { ?> <title>Add/Delete Recent News</title> <a href="../">Click Here to go home.</a> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <p>Title:<br> <input type="text" name="title" /></p> <p>Text:<br> <textarea rows="10" cols="50" name="news"></textarea></p> <p>Sticky: <input type="radio" name="sticky" value="y" /> YES | <input type="radio" name="sticky" value="n" /> NO</p> <input type="submit" name="postnews" value="Post News"> </form> </form> <br><br> <h4>Options:</h4> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <input type="submit" name="delete" value="Delete All News"> <input type="submit" name="delete[r]" value="Delete Non-Sticky News"> <input type="submit" name="delete[s]" value="Delete Sticky News"> </form> <u>Current features:</u> <br> <i>Quick Post News <br> Delete all regular news with one click <br> Delete all stickied news with one click <br> Option to title your news <br> "Sticky" News <br> Neatly displays all posted news in order from sticky to regular</i> <br><br><br> <u>Coming soon:</u> <br> <i>Ability to edit news <br> Ability to make stickied news regular and vise versa</i> <?php } ?> Error on "Delete all news": You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM news WHERE sticky='y'' at line 1 Error on "Delete sticky news": You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM news WHERE sticky='y'' at line 1 Non-Stickies have spaces in front of them on user end. Code posted above.. Source code of the page: <table> <tr> <th>STICKY: <u>Sticky</u></th> </tr> <tr> <td>Sticky</td> </tr> <tr> <th><u>Not</u></th> </tr> <tr> <td>Not</td> </tr> <tr> <th><u>Nothing</u></th> </tr> <tr> <td>Nothing</td> </tr> </table><br /> Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547519 Share on other sites More sharing options...
wildteen88 Posted May 22, 2008 Share Posted May 22, 2008 You're still using the old queries which are wrong. News.php should be: <?php require('config.php'); // Make a MySQL Connection mysql_connect("$path", "$username", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); if(isset($_POST['postnews'])) { $title = mysql_real_escape_string($_POST['title']); $news = mysql_real_escape_string($_POST['news']); //Check thate status of the sticky radio button $sticky = (isset($_POST['sticky']) && $_POST['sticky'] == 'y') ? 'y' : 'n'; //Insert the news $query = mysql_query("INSERT INTO news (title, news, sticky) VALUES ('$title', '$news', '$sticky')") or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'> News posted!"; } elseif(isset($_POST['delete'])) { //Delete all non-sticky news if(isset($_POST['delete']['r'])) { $qry = 'DELETE FROM news WHERE sticky=\'n\''; $msg = 'All <b>non-stickied</b> news deleted!'; } //Delete all stickied news if(isset($_POST['delete']['s'])) { $qry = 'DELETE FROM news WHERE sticky=\'y\''; $msg = 'All <b>stickied</b> news deleted!'; } //Delete all news else { $qry = 'TRUNCATE TABLE news'; $msg = 'All news deleted!'; } mysql_query($qry)or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'> $msg"; } else { ?> <title>Add/Delete Recent News</title> <a href="../">Click Here to go home.</a> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <p>Title:<br> <input type="text" name="title" /></p> <p>Text:<br> <textarea rows="10" cols="50" name="news"></textarea></p> <p>Sticky: <input type="radio" name="sticky" value="y" /> YES | <input type="radio" name="sticky" value="n" /> NO</p> <input type="submit" name="postnews" value="Post News"> </form> </form> <br><br> <h4>Options:</h4> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <input type="submit" name="delete" value="Delete All News"> <input type="submit" name="delete[r]" value="Delete Non-Sticky News"> <input type="submit" name="delete[s]" value="Delete Sticky News"> </form> <u>Current features:</u> <br> <i>Quick Post News <br> Delete all regular news with one click <br> Delete all stickied news with one click <br> Option to title your news <br> "Sticky" News <br> Neatly displays all posted news in order from sticky to regular</i> <br><br><br> <u>Coming soon:</u> <br> <i>Ability to edit news <br> Ability to make stickied news regular and vise versa</i> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547523 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 Cool, that fixed most of it.. Now there's 2 things.. 1.) If I click "Delete all news", it says "All stickied news deleted!!!" and I tried all 3 buttons and I never got a "All news deleted!"... 2.) Spaces in front of user end. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547531 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 3.) It doesn't show Stickies in first place. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547535 Share on other sites More sharing options...
wildteen88 Posted May 22, 2008 Share Posted May 22, 2008 Cool, that fixed most of it.. Now there's 2 things.. 1.) If I click "Delete all news", it says "All stickied news deleted!!!" and I tried all 3 buttons and I never got a "All news deleted!"... Change: //Delete all stickied news if(isset($_POST['delete']['s'])) to //Delete all stickied news elseif(isset($_POST['delete']['s'])) 2.) Spaces in front of user end. What spaces? 3.) ??? Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547539 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 Now for "Delete all", I'm getting "All non-stickied news deleted!"... And I mean this..: 1.) Their is spaces in front of the non stickies. 2.) I want Stickies to show in first place. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547544 Share on other sites More sharing options...
wildteen88 Posted May 22, 2008 Share Posted May 22, 2008 It is to do with the HTML code. Change the HTML to how you want the news to appear To always align news title text to the left. Change: <th>{$sticky}<u>{$news['title']}</u></th> to <th align="left"><u>{$sticky}{$news['title']}</u></th> Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547550 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 Cool!!! Now 1 thing left.. I want stickies to show before regular posts. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547552 Share on other sites More sharing options...
wildteen88 Posted May 22, 2008 Share Posted May 22, 2008 Change the order of the fields in the ORDER BY clause to: $query1 = "SELECT * FROM news ORDER BY sticky, id ASC"; should do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547557 Share on other sites More sharing options...
Cory94bailly Posted May 22, 2008 Author Share Posted May 22, 2008 Change the order of the fields in the ORDER BY clause to: $query1 = "SELECT * FROM news ORDER BY sticky, id ASC"; should do the trick. Cool!!! Yay it worked! Thank you so much wildteen! (Btw, you put part of your reply in the code tags.) If you could get a chance wildteen, please help me with a problem I'm posting now. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547562 Share on other sites More sharing options...
947740 Posted May 22, 2008 Share Posted May 22, 2008 EDIT: disregard. Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-547568 Share on other sites More sharing options...
Cory94bailly Posted May 23, 2008 Author Share Posted May 23, 2008 BUMP.. I forgot about this error! Now for "Delete all", I'm getting "All non-stickied news deleted!"... That's the last problem..! Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548332 Share on other sites More sharing options...
wildteen88 Posted May 23, 2008 Share Posted May 23, 2008 I suggested a fix earlier: Cool, that fixed most of it.. Now there's 2 things.. 1.) If I click "Delete all news", it says "All stickied news deleted!!!" and I tried all 3 buttons and I never got a "All news deleted!"... Change: //Delete all stickied news if(isset($_POST['delete']['s'])) to //Delete all stickied news elseif(isset($_POST['delete']['s'])) Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548443 Share on other sites More sharing options...
Cory94bailly Posted May 23, 2008 Author Share Posted May 23, 2008 Same thing happens... Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548452 Share on other sites More sharing options...
wildteen88 Posted May 23, 2008 Share Posted May 23, 2008 Post the code... Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548457 Share on other sites More sharing options...
Cory94bailly Posted May 23, 2008 Author Share Posted May 23, 2008 Post the code... <?php require('config.php'); // Make a MySQL Connection mysql_connect("$path", "$username", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); if(isset($_POST['postnews'])) { $title = mysql_real_escape_string($_POST['title']); $news = mysql_real_escape_string($_POST['news']); //Check thate status of the sticky radio button $sticky = (isset($_POST['sticky']) && $_POST['sticky'] == 'y') ? 'y' : 'n'; //Insert the news $query = mysql_query("INSERT INTO news (title, news, sticky) VALUES ('$title', '$news', '$sticky')") or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'> News posted!"; } elseif(isset($_POST['delete'])) { //Delete all non-sticky news if(isset($_POST['delete']['r'])) { $qry = 'DELETE FROM news WHERE sticky=\'n\''; $msg = 'All <b>non-stickied</b> news deleted!'; } //Delete all stickied news elseif(isset($_POST['delete']['s'])) { $qry = 'DELETE FROM news WHERE sticky=\'y\''; $msg = 'All <b>stickied</b> news deleted!'; } //Delete all news else { $qry = 'TRUNCATE TABLE news'; $msg = 'All news deleted!'; } mysql_query($qry)or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'> $msg"; } else { ?> <title>Add/Delete Recent News</title> <a href="../">Click Here to go home.</a> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <p>Title:<br> <input type="text" name="title" /></p> <p>Text:<br> <textarea rows="10" cols="50" name="news"></textarea></p> <p>Sticky: <input type="radio" name="sticky" value="y" /> YES | <input type="radio" name="sticky" value="n" /> NO</p> <input type="submit" name="postnews" value="Post News"> </form> </form> <br><br> <h4>Options:</h4> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <input type="submit" name="delete" value="Delete All News"> <input type="submit" name="delete[r]" value="Delete Non-Sticky News"> <input type="submit" name="delete[s]" value="Delete Sticky News"> </form> <u>Current features:</u> <br> <i>Quick Post News <br> Delete all regular news with one click <br> Delete all stickied news with one click <br> Option to title your news <br> "Sticky" News <br> Neatly displays all posted news in order from sticky to regular</i> <br><br><br> <u>Coming soon:</u> <br> <i>Ability to edit news <br> Ability to make stickied news regular and vise versa</i> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548458 Share on other sites More sharing options...
wildteen88 Posted May 23, 2008 Share Posted May 23, 2008 <?php require('config.php'); // Make a MySQL Connection mysql_connect("$path", "$username", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); if(isset($_GET['action']) && $_GET['action'] == 'add') { $title = mysql_real_escape_string($_POST['title']); $news = mysql_real_escape_string($_POST['news']); //Check thate status of the sticky radio button $sticky = (isset($_POST['sticky']) && $_POST['sticky'] == 'y') ? 'y' : 'n'; //Insert the news $query = mysql_query("INSERT INTO news (title, news, sticky) VALUES ('$title', '$news', '$sticky')") or die(mysql_error()); echo "<meta http-equiv='refresh' content='1;url={$_SERVER['PHP_SELF']}'> News posted!"; } elseif(isset($_GET['action']) && $_GET['action'] == 'del') { //Delete all non-sticky news if(isset($_POST['deln'])) { $qry = 'DELETE FROM news WHERE sticky=\'n\''; $msg = 'All <b>non-stickied</b> news deleted!'; } //Delete all stickied news elseif(isset($_POST['dels'])) { $qry = 'DELETE FROM news WHERE sticky=\'y\''; $msg = 'All <b>stickied</b> news deleted!'; } //Delete all news elseif(isset($_POST['dela'])) { $qry = 'TRUNCATE TABLE news'; $msg = 'All news deleted!'; } else { die('Invalid action'); } mysql_query($qry)or die(mysql_error()); echo "<meta http-equiv='refresh' content='1;url={$_SERVER['PHP_SELF']}'> $msg"; } else { ?> <title>Add/Delete Recent News</title> <a href="../">Click Here to go home.</a> <form action="<?php echo $_SERVER['PHP_SELF'] ?>?action=add" method="post"> <p>Title:<br> <input type="text" name="title" /></p> <p>Text:<br> <textarea rows="10" cols="50" name="news"></textarea></p> <p>Sticky: <input type="radio" name="sticky" value="y" /> YES | <input type="radio" name="sticky" value="n" /> NO</p> <input type="submit" name="postnews" value="Post News"> </form> </form> <br><br> <h4>Options:</h4> <form action="<?php echo $_SERVER['PHP_SELF'] ?>?action=del" method="post"> <input type="submit" name="dela" value="Delete All News"> <input type="submit" name="deln" value="Delete Non-Sticky News"> <input type="submit" name="dels" value="Delete Sticky News"> </form> <u>Current features:</u> <br> <i>Quick Post News <br> Delete all regular news with one click <br> Delete all stickied news with one click <br> Option to title your news <br> "Sticky" News <br> Neatly displays all posted news in order from sticky to regular</i> <br><br><br> <u>Coming soon:</u> <br> <i>Ability to edit news <br> Ability to make stickied news regular and vise versa</i> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548487 Share on other sites More sharing options...
Cory94bailly Posted May 23, 2008 Author Share Posted May 23, 2008 Worked! Thanks.. Solved Quote Link to comment https://forums.phpfreaks.com/topic/106106-solved-something-wrong/page/2/#findComment-548515 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.