This is a discussion on can't understand, it works or not within the MySQL forums, part of the Database Server Software category; --> query: SELECT `value` FROM `files_log` WHERE `phone_number` = "37063738282" AND used = "no" (works using phpmyadmin perfect, I get ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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? |
| |||
| On 5 Jul, 14:26, david <David.Abdurachma...@gmail.com> wrote: > 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? 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. |
| |||
| 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 wrote: > 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? > 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. |
| |||
| On 5 Jul, 15:04, david <David.Abdurachma...@gmail.com> wrote: > 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... 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. |
| |||
| On 5 Jul, 15:56, Captain Paralytic <paul_laut...@yahoo.com> wrote: > On 5 Jul, 15:04, david <David.Abdurachma...@gmail.com> wrote: > > > 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... > > 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. And if that doesn't work. Try writing it as a hard coded query with no php variables in it. |
| |||
| 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. |
| |||
| 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. |
| ||||
| On 5 Jul, 16:29, david <David.Abdurachma...@gmail.com> wrote: > 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. What's a "unique type"? |