-2

I have the following drop down list

    <form form action="" method="POST">
    <div class="w-container">
    <select class="w-select select-range" id="field" name="field" onchange='this.form.submit()'>
    <option value="range_1">select Week Range</option>
    <option value="Week 1" <?php if(isset($_POST['week']) && $_POST['week'] == 2){ ?> selected="selected" <?php } ?>>Week 2</option>
    <option value="Week 2" <?php if(isset($_POST['week']) && $_POST['week'] == 3){ ?> selected="selected" <?php } ?>>Week 3</option>
    </select>
    <noscript><input type="submit" value="submit"></noscript>
    </div>
</form>

And the I've got the following query

if(ISSET($_POST['week']))
  { $weekette = mysql_real_escape_string($_POST['week']); } 
else{($weekette=1);}
function query_create_games($weeker){


$query = "SELECT * FROM fixtures WHERE week=$weeker";

going through the while loop etc

Before I added the else{($weekette=1);} I was getting an error

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 '' at line 1

With the else there, it only returns results for week 1, when it should return results for week 2 or 3 respectively.

It seems as if the form isn't passing through the information to the post.

Am I missing something here?

potashin
  • 44,205
  • 11
  • 83
  • 107
Aasim Azam
  • 498
  • 2
  • 6
  • 23
  • 2
    Because strings like `Week 1` and `Week 2` need to be quoted in SQL statements.... though it's 2015 now, so you really should be using prepared statements with bind variables – Mark Baker Nov 01 '15 at 23:50
  • I know about using preparred statements, I am only doing this one temporary project just now offline so I don't need to really invest time in learning prepared statements yet. – Aasim Azam Nov 02 '15 at 00:04
  • @MarkBaker outlined that strings need to be in quotes..... so your query should look like `WHERE week = '$weeker'`.. – Darren Nov 02 '15 at 00:15

1 Answers1

0
$query = "SELECT * FROM fixtures WHERE week='$weeker'";

This should fix your problem.

Darren
  • 13,050
  • 4
  • 41
  • 79
rotvulpix
  • 468
  • 3
  • 9
  • 1
    Your answer may be right, but you should be outlining how to fix the problem so that the OP doesn't do it again and again. – Darren Nov 02 '15 at 00:16