MySQL problem

Discussion in 'PHP' started by ausgezeichnete, Dec 7, 2007.

  1. #1
    but please i have another problem in mysql query
    my select is
    i have records conatins :5,10,15 days
    every time i choose +/-7 days which has the values 7
    it gives me 0
    and when i select +/14 which has the value 14
    its gives me the days 5,15
    and when i select +/-21
    its gives me the days 5
    why????????
    and there is no sql error

    i think mysql query contains something wrong ???
     
    ausgezeichnete, Dec 7, 2007 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    hmm.. i dont see any problem with your post...
    i tried your script and it works, and with accurate output..

    you might want to check some . , ; chars on your script... ^^,
     
    bartolay13, Dec 7, 2007 IP
  3. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Have you debugged it by printing the $query to the screen to make sure it is what you expect. Check if you choose +/-7 your $query actually looks correct.
     
    Gawk, Dec 7, 2007 IP
  4. cocacolafun

    cocacolafun Peon

    Messages:
    119
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If days is an integer ... good practice ... don't put the single quotes.

    To debug ... find out what $days is ...

    Hacking Info: Also make sure to validate $days before to run the query ... otherwise, someone could hack and post your form with different values and hack into your database.
     
    cocacolafun, Dec 7, 2007 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    <?php
    mysql_connect("localhost","root","");
    mysql_select_db("practice");

    if($_POST)
    {
    $days = $_POST['days'];
    $query2="select user from rklb_user_accounts where id >= '". $days ."'";
    $query = mysql_query($query2);
    while($a = mysql_fetch_array($query))
    {
    echo $a['user'];
    }
    }
    ?>
    <body>



    <form method="POST">
    <select name="days" iid="days">
    <option value="7">+/-7 days</option>
    <option value="14">+/-14 days</option>
    <option value="21">+/-21 days</option>
    </select>
    <input type="submit" />
    </form>
    </body>

    here's my quick script..
     
    bartolay13, Dec 7, 2007 IP
  6. ausgezeichnete

    ausgezeichnete Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i echoed $days and it gave me the expected values
    i dont know what is wrong??
     
    ausgezeichnete, Dec 7, 2007 IP
  7. ausgezeichnete

    ausgezeichnete Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok tthnxxxx cocacolafun
    i was putting it as varchar in my database and when i changed it to int
    it worked just fine
    thnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
     
    ausgezeichnete, Dec 7, 2007 IP