Jump to content

[SOLVED] Something wrong =./


Cory94bailly

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

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 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 />

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

<?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
}
?>

Link to comment
Share on other sites

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.