Unix Technical Forum

can't understand, it works or not

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:10 AM
david
 
Posts: n/a
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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:11 AM
Captain Paralytic
 
Posts: n/a
Default Re: can't understand, it works or not

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 11:11 AM
david
 
Posts: n/a
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...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 11:11 AM
lark
 
Posts: n/a
Default Re: can't understand, it works or not

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 11:11 AM
david
 
Posts: n/a
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 11:11 AM
Captain Paralytic
 
Posts: n/a
Default Re: can't understand, it works or not

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 11:11 AM
Captain Paralytic
 
Posts: n/a
Default Re: can't understand, it works or not

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 11:11 AM
david
 
Posts: n/a
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 11:11 AM
david
 
Posts: n/a
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 11:11 AM
Captain Paralytic
 
Posts: n/a
Default Re: can't understand, it works or not

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"?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com