Cory94bailly Posted May 8, 2008 Share Posted May 8, 2008 Ok.. this time, I am actually having problems with a php script.. Here it is (secret info = ***): <?php if(isset($_POST['submit'])) { // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); $title = mysql_real_escape_string($_POST['title']); $news = mysql_real_escape_string($_POST['news']); // Insert the news $query = mysql_query("INSERT INTO news (title, news) VALUES ('$title', '$news')")or die(mysql_error()); echo "News posted!<br><a href='test1.php'>Click here to view the news!</a>"; if(isset($_POST['delete'])) { // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); // Delete it all mysql_query("TRUNCATE TABLE news")or die(mysql_error()); echo "All news deleted!<br><a href='test1.php'>Click here to check!</a>"; } } else { ?> <h2>This is the <i>admin end</i> of my php news script.. Still working on it though xD </h2 <form action="<? $_SERVER['PHP_SELF']; ?>" method="post"> Title: <input type="text" name="title"></input><br><br> Text: <textarea rows="10" cols="50" name="news"></textarea> <input type="submit" name="submit" value="Submit"> </form> <h4>Options:</h4> <form action="<? $_SERVER['PHP_SELF']; ?>"; method="post"> <input type="submit" name="delete" value="Delete all news"> </form> <?php } ?> I've been working on it for a couple hours now... Test it: http://www.etsoldiers.com/testing123/test2.php You can add news and everything but it won't delete.. I tried it a different way a little while ago but it would always include some other stuff that way.. Any help? (I think it might be my brackets..) Quote Link to comment https://forums.phpfreaks.com/topic/104754-solved-not-working/ Share on other sites More sharing options...
wildteen88 Posted May 8, 2008 Share Posted May 8, 2008 Change this: if(isset($_POST['delete'])) { // Delete it all mysql_query("TRUNCATE TABLE news")or die(mysql_error()); echo "All news deleted!<br><a href='test1.php'>Click here to check!</a>"; } } else { to: } elseif(isset($_POST['delete'])) { // Delete it all mysql_query("TRUNCATE TABLE news")or die(mysql_error()); echo "All news deleted!<br><a href='test1.php'>Click here to check!</a>"; } else { That should sort the problem. Also no need to connect/select database in each if statement. Just have one instance of that portion of code. So remove the following code: // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); from your if blocks and chnage the following line: <?php if(isset($_POST['submit'])) { to <?php // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); if(isset($_POST['submit'])) { Quote Link to comment https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536238 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 Cool, it all worked.. Thanks so much! I'm still learning but I'm getting better (I hope...) Quote Link to comment https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536243 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 Hold on a second... I want to add a confirm box to delete all news. How would I do that? I kinda see how but it's confusing me at the moment.. Damn curly brackets! And one more for this topic is: How could I add the option to edit a topic? Quote Link to comment https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536247 Share on other sites More sharing options...
dezkit Posted May 8, 2008 Share Posted May 8, 2008 for the confirm box for deleting news, use javascript, for option to edit a topic, read this -> http://www.tizag.com/mysqlTutorial/mysqlupdate.php Quote Link to comment https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536292 Share on other sites More sharing options...
Cory94bailly Posted May 8, 2008 Author Share Posted May 8, 2008 for the confirm box for deleting news, use javascript I tried but it failed.. I got a code off w3schools and put it in.. Then I went to test it.. the boxes didn't appear, it just did the task. Quote Link to comment https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536298 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.