PHP forum

Sql query not working

Aug 7, 2009 7:19 pm
Geoff Cox

Hello,

I have the following sql line

$query = "select * from codes where " . user_code . "= binary " . "'"
. $result1 . "'" . "&&" . user_password . "= binary " . "'" . $result2
. "'" . "&&" . demo . "='yes'";

which works fine but if I use

. demo . "!='yes'

when a demo field in the mysql table ( varchar / not null) and has
had no value added to it, this does not work.

Can you see why?

Thanks

Geoff

Aug 7, 2009 7:38 pm
Geoff Cox
Re: sql query not working

On Fri, 07 Aug 2009 20:19:29 +0100, Geoff Cox <gcox@freeuk.com> wrote:

>Hello,
>
>I have the following sql line
>
>$query = "select * from codes where " . user_code . "= binary " . "'"
>. $result1 . "'" . "&&" . user_password . "= binary " . "'" . $result2
>. "'" . "&&" . demo . "='yes'";
>
>which works fine but if I use
>
>. demo . "!='yes'
>
>when a demo field in the mysql table ( varchar / not null) and has
>had no value added to it, this does not work.

I should have added that if I add 'no' to a demo field then

"='no'

works so cannot see why

"!='yes'

does not work for a demo field with nothing added to it?

Cheers

Geoff


>
>Can you see why?
>
>Thanks
>
>Geoff


Aug 7, 2009 8:13 pm
Doug Miller
Re: sql query not working

In article <08vo75hr2enj0fias04ei0o7serovosgnc@4ax.com>, Geoff Cox <gcox@freeuk.com> wrote:
>Hello,
>
>I have the following sql line
>
>$query = "select * from codes where " . user_code . "= binary " . "'"
>.. $result1 . "'" . "&&" . user_password . "= binary " . "'" . $result2
>.. "'" . "&&" . demo . "='yes'";
>
>which works fine but if I use
>
>.. demo . "!='yes'
>
>when a demo field in the mysql table ( varchar / not null) and has
>had no value added to it, this does not work.

I'm not surprised.
>
>Can you see why?

The inequality operator in standard SQL is not '!='. It's '<>'.


Aug 7, 2009 9:18 pm
Geoff Cox
Re: sql query not working

On Fri, 07 Aug 2009 20:13:15 GMT, spambait@milmac.com (Doug Miller)
wrote:

>In article <08vo75hr2enj0fias04ei0o7serovosgnc@4ax.com>, Geoff Cox <gcox@freeuk.com> wrote:
>>Hello,
>>
>>I have the following sql line
>>
>>$query = "select * from codes where " . user_code . "= binary " . "'"
>>.. $result1 . "'" . "&&" . user_password . "= binary " . "'" . $result2
>>.. "'" . "&&" . demo . "='yes'";
>>
>>which works fine but if I use
>>
>>.. demo . "!='yes'
>>
>>when a demo field in the mysql table ( varchar / not null) and has
>>had no value added to it, this does not work.
>
>I'm not surprised.
>>
>>Can you see why?
>
>The inequality operator in standard SQL is not '!='. It's '<>'.

Thanks for your reply Doug.

I've tried <> and still not working. Also when I use a phpmyadmin
search for not equal the sql shown uses !=. This is the php syntax and
I should have said the sql above is in a php file.

Geoff




Previous Thread: Migrate PHP 2.0 code to PHP 5.x
Next Thread: Looping through an object

Related Forum Topics
Assign the result of $db->query($query) to a variable ???
I'm creating tabs using PHP/MySQL and jQuery. I've created the easiest
model for testing purposes:

<div class="tab">

<div class="tab-nav">
<ul>
<li><a href="#1" />1</li>
<li><a href="#2" />2</li>
<li><a href="#3" />3</li>
</ul>
</div>

<div id="1"...
Defines not working
I have the following style of define in my code and they appear not to work:

define('myPrefix','Prefix') ;
define('item_1',myPrefix.'_1') ;
etc ...

The second define exapnds as myPrefix_1 instead of Prefix_1, any suggestions
what I am doing wrong?
Thanks,
Sid.



Got it working finally
www.mroldies.net

At least it is functioanl as I want it.


Query Question
I have a php query that is querying a mysql db table and I'm passing
along the variable contents of 'keyword' from an input form. From
there, I'm trying to query two different db table columns of data.
I'm hopeful to be able to pick up a word like 'roof' as the keyword
and if it exists...
Query string
Is there a simple php function for getting the query string, ie
everything after the "?".

I can't find it in the manual, but php has so many functions, I'm
thinking it might exist.

Jeff


PDO Query Syntax
Suppose that I have a table SomeTable in my database with a column
called SomeColumn and I wish to select the first line of this table.
To do this in firebird I use:
"Select First 1 SomeColumn From SomeTable"
in Microsoft SQL Server I use
"Select Top 1 SomeColumn From SomeTable"
and in...
ODBC not working with PHP under Eclipse
Hi,
I'm trying to debug a simple page of PHP under Eclipse, with Zend
debugger.
I'm working on a local machine with Windows XP, IIS and SqlServer.

The problem is:
- if I run the PHP script directly from a browser, it's all OK (I can
connect to a db using odbc and execute queries).
- if I...
Isset not working with select
http://mroldies.net/showtable.php?year=1960



$result = mysql_query("SELECT acover,bcover FROM A$year WHERE id =
$number");
if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }
$cov = mysql_fetch_row($result);


if (isset($cov[0]))
{echo "<img...
Session stopped working?
I've been using FF2.n in developing a hideously complex FAMP app.
Last week, session seemed to stop working for no good reason. I
went into my zen-of-debugging mode, and investigated everything
in greater and greater depth, feeling sure I was somehow stepping
on something without realising...
Code Stops Working
I have assumed ownership of a site that has a lot of PHP code - and I
don't have much experience with the language and environment. The site
is:

www.raceplaceevents.com

The situation is that I've made a small change to one of the sub-
pages that seems to render it not working. ...