Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:00:14+00:00 2026-06-03T01:00:14+00:00

So I have a table on a server that saves posts that users enter.

  • 0

So I have a table on a server that saves posts that users enter. On this final page where you can view them, you can choose to either view everyones result, or , pick just a certain weather to view. The picking certain weather part is working, but if you choose the ‘all’ option, it wont show anything. Any idea’s why?

View Posts 
<br>
<form method="get" action="view_forum.php">
    <label>Select Weather to Filter </label><br />
    <select name="weather">
        <option value="all">all</option>
        <option value="cloudy">Cloudy</option>
        <option value="sunny">Sunny</option>
        <option value="windy">Windy</option>
        <option value="snowy">Snowy</option>
        <option value="mixy">Wintery Mix</option>
        <option value="rainy">Rainy</option>
    </select>
    <input type="submit" value="view" />
</form>

<div id="view">
    <center><img src="images/forum.png" width="589" height="97"></center>
</div>  

<div id="white">
    <div id="blue">
        <div id="grey">
            <div id="container">        
<?php

    $dbc = mysql_connect('html','user','password','database');
    mysql_select_db('database',$dbc);

    $weather = sanitize( $_GET["weather"] ); // keep your input clean

    if ( $weather == "all" ) {
        $sql = "SELECT * FROM stories ORDER BY id DESC";
    } else {
        $sql = "SELECT * FROM stories WHERE weather = '$weather' ORDER BY id DESC";
    }

    while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {
        echo "<div class=\"names\"> {$row['name']}<br /></div>";
        echo "<div class=\"weathers\">{$row['weather']}<br /></div>";
        echo "<div class=\"stories\">{$row['story']}<br /></div>";
        echo "<img src=\"images/line.png\" width='800' height='3'>";
        echo "<br />";  
    }
?>
            </div>
        </div>
    </div>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:00:16+00:00Added an answer on June 3, 2026 at 1:00 am

    You should really watch out for sql injections, and if possible move over to mysqli_prepare, or PDO prepared
    query’s.

    But your main problem is that your doing a query for all which unless you have weather called all it wont find it.

    The solution is to check for the all option and change the query depending on that.

    Also if $_GET['weather'] is not set you need a default, I suspect you also have error reporting off and its not throwing a Notice:Undefined an error.

    <?php 
    if(isset($_GET['weather'])){
        $_GET['weather']=mysql_real_escape_string($_GET['weather']);
        //All
        if($_GET['weather'] == 'all'){
            $sql = "SELECT * from stories ORDER BY id DESC";
        }else{
            //Specific
            $sql = "SELECT * from stories WHERE weather='{$_GET['weather']}' ORDER BY id DESC";
        }
    }else{
        //Default
        $sql = "SELECT * from stories ORDER BY id DESC";
    }
    ?>
    

    UPDATE (Full code, with fixes):

    <?php 
    $dbc=mysql_connect('html','user','password','database') or die(mysql_error());
    mysql_select_db('database',$dbc) or die(mysql_error());
    ?>
    
    View Posts <br>
    <form method="get" action="view_forum.php">
      <label>Select Weather to Filter </label><br />
      <select name="weather">
        <option value="all">all</option>
        <option value="cloudy">Cloudy</option>
        <option value="sunny">Sunny</option>
        <option value="windy">Windy</option>
        <option value="snowy">Snowy</option>
        <option value="mixy">Wintery Mix</option>
        <option value="rainy">Rainy</option>
      </select>
      <input type="submit" value="view" />
    </form>
    
    <div id="view">
     <center><img src="images/forum.png" width="589" height="97"></center>
    </div>  
      <div id="white">
        <div id="blue">
          <div id="grey">
           <div id="container">
    <?php
    if(isset($_GET['weather'])){
    $_GET['weather']=mysql_real_escape_string($_GET['weather']);
        //All
        if($_GET['weather'] == 'all'){
            $sql = "SELECT `name`,`weather`,`story`
                    FROM stories 
                    ORDER BY id DESC";
        }else{
            //Specific
            $sql = "SELECT `name`,`weather`,`story`
                    FROM stories 
                    WHERE weather='{$_GET['weather']}' 
                    ORDER BY id DESC";
        }
    }else{
        //Default
        $sql = "SELECT `name`,`weather`,`story`
                FROM stories 
                ORDER BY id DESC";
    }
    
    $result = mysql_query($sql);
    
    if(mysql_num_rows($result)>0){
        while($row=mysql_fetch_assoc($result)){
            echo "<div class=\"names\"> {$row['name']}<br /></div>";
            echo "<div class=\"weathers\">{$row['weather']}<br /></div>";
            echo "<div class=\"stories\">{$row['story']}<br /></div>";
            echo "<img src=\"images/line.png\" width='800' height='3'>";
            echo "<br />";
        }
    }else{
        echo 'No results';
    }
    ?>
    </div>
    </div>
    </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which contains my ads that can be searched in sql-server-2008.
Ok I have a table in my SQL Server database that stores comments. My
I have an user defined table function in SQL Server that aggregate data from
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a SQL Server table in production that has millions of rows, and
I have a SQL Server DB that has a table of products, and another
I have a junction table in my SQL Server 2005 database that consist of
I have an ADOQuery that inserts a record to SQL Server 2005 table that
I'm using SQL Server 2008 and I have a table that has a 'Status'
I need to copy a table from one server to another.for that I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.