Professional Web Applications Themes

can't understand, it works or not - MySQL

query: SELECT `value` FROM `files_log` WHERE `phone_number` = "37063738282" AND used = "no" (works using phpmyadmin perfect, I get all results I want) But in PHP: $data_sql = 'SELECT `value` FROM `files_log` WHERE `phone_number` = "'. $phone_number.'" AND used = "no"'; $data = db_query($data_sql); while ($row = mysql_fetch_row($data)) $pay += $row[0]; I get: 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 So, where is that mistake? What I have missed?...

  1. #1

    Default can't understand, it works or not

    query: SELECT `value` FROM `files_log` WHERE `phone_number` =
    "37063738282" AND used = "no" (works using phpmyadmin perfect, I get
    all results I want)

    But in PHP:
    $data_sql = 'SELECT `value` FROM `files_log` WHERE `phone_number` = "'.
    $phone_number.'" AND used = "no"';
    $data = db_query($data_sql);
    while ($row = mysql_fetch_row($data))
    $pay += $row[0];

    I get: 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

    So, where is that mistake? What I have missed?

    david Guest

  2. #2

    Default Re: can't understand, it works or not

    On 5 Jul, 14:26, david <com> wrote: 

    I would suggest writing

    $data_sql = "SELECT `value` FROM `files_log` WHERE `phone_number` =
    '$phone_number' AND `used` = 'no'";

    as it is far easier to see what is going on.

    Next I would suggest you echo the value of $data_sql to see what the
    query actually looks like.

    Then post that output for us to see.

    Captain Guest

  3. #3

    Default Re: can't understand, it works or not

    SELECT `value` FROM `files_log` WHERE `phone_number` = "37063738282"
    AND used = "no"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

    it's looks the same...

    david Guest

  4. #4

    Default Re: can't understand, it works or not

    david wrote: 

    how about
    $data_sql = "select `value` from `files_log` where `phone_number` = \""
    ..$phone_number."\" and used =\""no"\";

    try it with back ticks as you see it above and without as well.
    lark Guest

  5. #5

    Default Re: can't understand, it works or not

    Yeah, but the result is exactly the same. I just can't understand what
    I have missed, the syntax looks without any errors for me and I just
    tested it again in phpmyadmin and it works :(

    david Guest

  6. #6

    Default Re: can't understand, it works or not

    On 5 Jul, 15:04, david <com> wrote: 

    Please do what I suggested you do.

    rewrite it as:

    $data_sql = "SELECT `value` FROM `files_log` WHERE `phone_number` =
    '$phone_number' AND `used` = 'no'";

    and run it again.

    Captain Guest

  7. #7

    Default Re: can't understand, it works or not

    On 5 Jul, 15:56, Captain Paralytic <com> wrote: 

    >
    > Please do what I suggested you do.
    >
    > rewrite it as:
    >
    > $data_sql = "SELECT `value` FROM `files_log` WHERE `phone_number` =
    > '$phone_number' AND `used` = 'no'";
    >
    > and run it again.[/ref]

    And if that doesn't work. Try writing it as a hard coded query with no
    php variables in it.

    Captain Guest

  8. #8

    Default Re: can't understand, it works or not

    The same result, but I found something interesting.

    `used` field's type: enum('no', 'yes')

    The same code works if I set "AND `used` = 'yes'" or any other word,
    but not 'no'. If I write 'no' it doesn't work, I get that error.

    david Guest

  9. #9

    Default Re: can't understand, it works or not

    Fixed, but still thanks for the help. The problem was with the table,
    it looks like somehow I had two unique types on the same column,
    sounds a bit strange, but after changing that everything works as it
    should be. Good night for everybody and again thanks for your effort
    to help me.

    david Guest

  10. #10

    Default Re: can't understand, it works or not

    On 5 Jul, 16:29, david <com> wrote: 

    What's a "unique type"?

    Captain Guest

  11. #11

    Default Re: can't understand, it works or not

    david wrote: 

    do a little bit of debugging:

    echo $sql_data;

    this will print the loaded var into your browser. you'd then be able to
    see what is missing.
    lark Guest

Similar Threads

  1. #39370 [NEW]: $_GET no longer works under FastCGI but works under CGI.
    By trustpunk at gmail dot com in forum PHP Bugs
    Replies: 7
    Last Post: November 9th, 10:38 AM
  2. please help me understand..
    By Ramesh in forum Linux / Unix Administration
    Replies: 3
    Last Post: February 20th, 11:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139