Jump to content

[SOLVED] Not working?


Cory94bailly

Recommended Posts

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..)

Link to comment
https://forums.phpfreaks.com/topic/104754-solved-not-working/
Share on other sites

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'])) {

Link to comment
https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536238
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/104754-solved-not-working/#findComment-536247
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.