php-general Digest 5 Sep 2007 11:53:37 -0000 Issue 5001

Topics (messages 261705 through 261720):

Re: PHP Developer Required]
        261705 by: tedd
        261720 by: mlists

Re: Dealing with auto-increment in MySQL
        261706 by: brian
        261708 by: tedd

Re: Pragmatically changing a "Record Number"
        261707 by: tedd
        261710 by: brian

Re: MySQL, PHPMyAdmin, GRANT, headaches
        261709 by: tedd

Re: Command line socket server and SSL
        261711 by: Chris
        261712 by: Paul
        261714 by: Greg Donald
        261715 by: Paul

Re: urldecode & header
        261713 by: Greg Donald

Re: Bind function parameters with create_function ('currying')]
        261716 by: Richard Heyes

Problem With mysql_query
        261717 by: Brian Welter
        261718 by: Zoltán Németh
        261719 by: Stut

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
At 4:05 PM -0400 9/4/07, Robert Cummings wrote:
On Tue, 2007-09-04 at 14:28 -0400, Greg Gay wrote:
 > Rob/mlists

So, you can get that much?  :-)

I knew my MSc would pay off some day.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
A university, which hypes the need for an education, charges a fortune
for it (causing people to go into massive debt to get it), and then
turns around an offers less than a living wage is hypocritical.

"Becoming university staff takes a couple years, after which salaries
are competivitive with the going rates."  So for the first couple of
years you get taken advantage of and then, maybe, you will get paid
more!

That is just not fair.



On Tue, 2007-09-04 at 14:28 -0400, Greg Gay wrote:
> Rob/mlists
> 
> You're certainly not encouraging PHP programmers to get involved with
> paid open source projects. That's a guaranteed $50,000 a yr, a little
> low perhaps by industry standards, but it is a reasonable starting rate,
> and gets your foot in the door.
> 
> You should have a look at who the employer is, and what they do. They
> (we) are
> looking for a person who has done their research. This is more than
> just a job. It has the potential to introduce applicants to a world of
> experience, not just code crunching, but getting involved with the
> groups who introduce new technologies and working on leading edge
> projects (groups like the W3C, IMS, ISO, AICC, and many others) .
> Experiences you won't get as a programmer for your average software
> developer. The ATRC is involved with most standards bodies around the
> world, and has dozen of open source projects on the go.
> 
> Becoming university staff takes a couple years, after which salaries are
> competivitive with the going rates. Not to mention a full set of
> benefits, pension, excellent working environment, including flexible
> working hours, travel benefits, free university course (get a masters or
> phd for nothing) etc. Most staff start on a casual/contract basis before
> being moved into the main stream. Our established programmers do earn in
> the 90-100G per year, with benefits on top of that. All included, that's
> somewhere in the $60/hr range, with $0 expenses.
> 
> You're auto machanic btw, has overhead included in that rate, so that's
> a rather poor comparison. How much do you think he really makes an hour,
> after paying expenses out of that $99? And of course 4% isn't a bonus.
> Contract workers are paid that weekly, while staff accumulate it so they
> can take holidays and get paid.
> 
> 
> greg
> 
> 
> 
> 
> Robert Cummings wrote:
> > On Mon, 2007-09-03 at 13:47 -0400, mlists wrote:
> >
> >>Wow!
> >>
> >>Spend $100K on a university degree in computer science, work
> >>successfully for five years with all the major technologies, and then
> >>get paid $25 per hour?
> >
> >
> > The poster didn't mention anything about being competent.
> >
> >
> >>My auto mechanic charges an average of $99 per hour.
> >>
> >>Sounds like a great deal for the university. Maybe the successful
> >>candidate can work off his student loans.
> >
> >
> > Well 100k is a bit high for a 4 year program. And then again it depends
> > on whether you had to move away from your parents to attend university.
> > If you live within commute range of your university then you can get
> > away with 20 to 30k expenses in Canada (depending on University). If you
> > have to cover rent then it's a different story :) That said, Toronto is
> > one of the most expensive cities in Canada in which to live. IMHO he
> > still thinks the tech sector is in a depression and developers with 5
> > years experience can be had for a pittance. What made me laugh was the
> > "4%" vacation pay. That's a legal requirement in Canada for full time
> > employment. Not a bonus.
> >
> > Cheers,
> > Rob.
> 

--- End Message ---
--- Begin Message ---
tedd wrote:
Jason:

Well, at least you read and comprehended what was said -- that's better than some.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com


Nice. Good luck with your database endeavours!

brian

--- End Message ---
--- Begin Message ---
At 8:12 PM -0400 9/4/07, brian wrote:
tedd wrote:
Jason:

Well, at least you read and comprehended what was said -- that's better than some.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com


Nice. Good luck with your database endeavours!

brian

Never had any problems before.

And, good luck with clients.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
At 12:11 PM -0400 9/4/07, brian wrote:
tedd wrote:
At 6:18 PM -0400 9/3/07, brian wrote:

It may be just fine in your case, but from a DB design standpoint it most certainly is not efficient. Why re-order the entire table for something like this? Altering an entire table because one row has been deleted suggests to me that the schema needs to revisited.

...

However, we (or at least I) often work with clients who don't see that. Instead they see records that they place into their database that hold information about their widgets and they like to see a record number associated with their widget. And, when they add a new widget record, they want to see that count increased and when they delete a widget record they want to see it gone and a gap, where they can renumber at their will.

You are confusing a product ID with this index number. They are very much not the same thing. A product ID (PLU, serial #, whatever) should not change. This index does change, any time a row is removed from the database. How can you suggest that this index can be "associated with their widget" if the value can change at any time? There's no one-to-one relationship between the widget and this index. At least, not over the life of the widget's record in the database.


No, the problem is not that I am confusing widget numbers, but rather your definition of what widget numbers should be doesn't meet the needs of the client. You have one note in your songbook.

The problem here is that you're being argumentative instead of trying to understand that not everyone is limited to your perspective. I've understood everything that you've said, and agree with most of it, but you fail to acknowledge a single statement I've made. This is very similar to how we started this thread in the first place when you completely misread something I wrote and then turned it all around to your liking. Apparently, you are doing it again.

The client I have, who wants his record numbers to work the way I described, is a photographer. When he works with his db of pictures he wants to see record numbers as he steps through his listing. If he see's something he wants to edit in his database, then he wants write down that record number so that he can go back and find it again during that specific editing session. Likewise, if he wants to remove a picture from his from his database, then it he wants it to be gone now.

He understands, and doesn't care, that the next time he travels through his database that the numbers above his last deletion have changed. In fact, I don't even have to keep the numbers in a field in his database -- instead I could easily use the creation data-stamp for a sort and present his pictures to him that way. But, he wants that field number there, so that he can continue his editing later, if he decides to quit -- he wants his current editing session to remain "as-is" until he changes it -- so the field is there for him.

The point is -- this is an example of a reference number that the client wants and uses successfully. Who am I to argue with him. In fact, who is anyone to argue with something that works for him? You? You want to impose your view of how he should work? Keep in mind, this is the client and they say, and pay for, what they want.

I think you'll find in life that not all aspects of dealing with clients fall nicely into the way you think things should be done. It's probably best for you to get used to it now than later.

Enough said on this subject, besides I don't think you're reading what I write correctly anyway.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
tedd wrote:
At 12:11 PM -0400 9/4/07, brian wrote:

You are confusing a product ID with this index number. They are
very much not the same thing. A product ID (PLU, serial #,
whatever) should not change. This index does change, any time a row
is removed from the database. How can you suggest that this index
can be "associated with their widget" if the value can change at
any time? There's no one-to-one relationship between the widget and
this index. At least, not over the life of the widget's record in
the database.

No, the problem is not that I am confusing widget numbers, but rather
 your definition of what  widget numbers should be doesn't meet the
needs of the client. You have one note in your songbook.

I have not once "defined" what a widget number, product code, whatever
should be. You're imagining things now. There LARGE_NUMBER of formats
that a "widget number" can have. I couldn't care less how you (or your
client) chooses to do so.

The problem here is that you're being argumentative instead of trying
to understand that not everyone is limited to your perspective. I've
 understood everything that you've said, and agree with most of it,
but you fail to acknowledge a single statement I've made. This is
very similar to how we started this thread in the first place when
you completely misread something I wrote and then turned it all
around to your liking. Apparently, you are doing it again.

Why are you getting all pissy now? I certainly haven't been. Have i not
been including enough smileys or something?

The client I have, who wants his record numbers to work the way I described, is a photographer. When he works with his db of pictures
he wants to see record numbers as he steps through his listing. If he
see's something he wants to edit in his database, then he wants write
down that record number so that he can go back and find it again
during that specific editing session. Likewise, if he wants to remove
a picture from his from his database, then it he wants it to be gone
now.

Well, if your client needs to print out something that relates back to the record, print out the primary key. Print out the PLU.. Print out the [insert UNIQUE_VALUE here].

Better yet: design the app so your client doesn't have to get out a pencil. But i digress ...

He understands, and doesn't care, that the next time he travels
through his database that the numbers above his last deletion have
changed. In fact, I don't even have to keep the numbers in a field in
his database

So why all the fuss about having to keep this problem-child "index"
field in the table, then? If it doesn't have to be in there then why are you insisting on including it?

-- instead I could easily use the creation data-stamp for a sort and
 present his pictures to him that way. But, he wants that field
number there, so that he can continue his editing later, if he
decides to quit -- he wants his current editing session to remain
"as-is" until he changes it -- so the field is there for him.

The point is -- this is an example of a reference number that the
client wants and uses successfully. Who am I to argue with him. In
fact, who is anyone to argue with something that works for him? You?
You want to impose your view of how he should work? Keep in mind,
this is the client and they say, and pay for, what they want.

Not one thing that you've described here comes anywhere close to making a case for designing a database schema in such a manner. All of the above can be accomplished without having to re-order your table each time a record is removed.

I think you'll find in life that not all aspects of dealing with
clients fall nicely into the way you think things should be done.
It's probably best for you to get used to it now than later.

You're being pissy again. It really reflects poorly on you and, i suspect, it's keeping you from truly understanding what it is that i'm trying to help you with.

Enough said on this subject, besides I don't think you're reading
what I write correctly anyway.

I read it twice ("correctly", even!). Mostly because your stubborness fascinates me. Like a moth to a flame, really.

brian :-)

--- End Message ---
--- Begin Message ---
At 3:00 PM -0400 9/4/07, brian wrote:
I'm setting up a site and am having loads of problems with MySQL (which i don't use much, being a Postgres fan). The server is not controlled by myself and I'm waiting on a reply from the admin. In the meantime:

PHP 4.3.9
Mysql 4.1.10a (server) 3.23.49 (client)

The database has been set up along with PHPMyAdmin (i also rarely use this). I have been provided with a user & pass for PHPMyAdmin, as well as a user & pass for the DB. Using the former, i have created the tables and copied in my data. Within that interface, i can make any query i'd like.

However, from within a PHP script (and using the second user & pass), i seem to be SOL. Even the most basic queries return empty results. Debugging has been a royal pain because interfaces such as MDB2, DB, etc. are also not available. That means relying on mysql_error() which is frustrating.

After much dicking around, i've come to the conclusion that the problem must be that the user does not have permission to select from the DB. A comment on the mysql_error() manual page [1] says that, in the case of "Access denied ..." mysql_error() returns the empty string.

I feel like i've taken crazy pills! Please, someone tell me this isn't true! How does one debug a problem like this? How can i know if i have SELECT rights to the table?

[1] http://ca3.php.net/manual/en/function.mysql-error.php#44168

brian


Show us your code.

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Paul wrote:
I need to program a socket server in PHP that can use a certificate and communicate over SSL. I'm doing fine without SSL. Can't use port 443 or the web server for this, so it needs to be a command line app. Can't seem to find any documentation about how to set that up. Can anyone help or point me in the right direction?

Which part do you need help with? The SSL part or the command line or the port or ... ?

http://www.php.net/openssl
http://www.php.net/sockets

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Chris wrote:
Paul wrote:
I need to program a socket server in PHP that can use a certificate and communicate over SSL. I'm doing fine without SSL. Can't use port 443 or the web server for this, so it needs to be a command line app. Can't seem to find any documentation about how to set that up. Can anyone help or point me in the right direction?

Which part do you need help with? The SSL part or the command line or the port or ... ?

http://www.php.net/openssl
http://www.php.net/sockets

I am familiar with the above links. What I cannot locate is anything that indicates that a cmd line socket program in PHP can do SSL. Can you locate such? Is it in the openssl document somewhere and I missed it?

Paul W

--- End Message ---
--- Begin Message ---
On Tue, 4 Sep 2007, Paul wrote:
> > Which part do you need help with? The SSL part or the command line or the
> > port or ... ?
> >
> > http://www.php.net/openssl
> > http://www.php.net/sockets
> >
> I am familiar with the above links. What I cannot locate is anything that
> indicates that a cmd line socket program in PHP can do SSL. Can you locate
> such? Is it in the openssl document somewhere and I missed it?

Whether the script is command line or not has nothing to do with it's ability 
to connect to a host on a specific port.  You just connect to the port the 
secure socket is located on, usually 443.

#!/usr/bin/env php
<?php
$s = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_set_nonblock( $s );
socket_connect( $s, "example.com", 443 );
socket_set_block( $s );
switch( socket_select( $r = array( $s ), $w = array( $s ), $f = array( $s ), 5 
) )
{
    case 2:
        echo "[-] Connection Refused\n";
        break;
    case 1:
        echo "[+] Connected\n";
        break;
    case 0:
        echo "[-] Timeout\n";
        break;
}


-- 
Greg Donald
Cyberfusion Consulting
http://cyberfusionconsulting.com/

--- End Message ---
--- Begin Message --- Below you have described a client. I'm talking about a server. That was clear in my original post.
-Paul W

Greg Donald wrote:
On Tue, 4 Sep 2007, Paul wrote:
Which part do you need help with? The SSL part or the command line or the
port or ... ?

http://www.php.net/openssl
http://www.php.net/sockets

I am familiar with the above links. What I cannot locate is anything that
indicates that a cmd line socket program in PHP can do SSL. Can you locate
such? Is it in the openssl document somewhere and I missed it?

Whether the script is command line or not has nothing to do with it's ability 
to connect to a host on a specific port.  You just connect to the port the 
secure socket is located on, usually 443.

#!/usr/bin/env php
<?php
$s = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_set_nonblock( $s );
socket_connect( $s, "example.com", 443 );
socket_set_block( $s );
switch( socket_select( $r = array( $s ), $w = array( $s ), $f = array( $s ), 5 
) )
{
    case 2:
        echo "[-] Connection Refused\n";
        break;
    case 1:
        echo "[+] Connected\n";
        break;
    case 0:
        echo "[-] Timeout\n";
        break;
}



--- End Message ---
--- Begin Message ---
On Tue, 4 Sep 2007, alexus wrote:
> i have a form that user suppose to fill out that then get submitted to
> index.php (current setup)
>
> now what i need is another let's say index2.php that would take
> everything from that form, rewrite one of the field and spits it back
> to index.php
>
> now, i dont know but as far as i know stuff that form spits out is
> urlencoded, so i need to use urldecode function (
> http://us.php.net/urldecode ) to decode and then header function (
> http://us2.php.net/header ) to spit it back to index.php

urlencode() and urldecode() are handy for passing text in urls.

In index.php you would have something like:

$msg = urlencode( 'whatever message you want to send' );

header( "Location: http://example.com/index2.php?msg=$msg"; );
exit;

Then on the index2.php

$msg = isset( $_REQUEST[ 'msg' ] ) ? urldecode( $_REQUEST[ 'msg' ] ) : '';

At this point you can mangle $msg however you like and send it somewhere
else with another header() call.



-- 
Greg Donald
Cyberfusion Consulting
http://cyberfusionconsulting.com/

--- End Message ---
--- Begin Message ---

--
Richard Heyes
+44 (0)800 0213 172
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support
--- Begin Message ---
Of course, my apologies.
I've simplified it from the actual code and also removed the string
parameter as the object one is the problem:

// create the model and replacer function
> $model = new $modelName();
> $replacer = curryModelReplacer($($model);
> // ...
>
> /** Curries model_replacer. */
> function curryModelReplacer($model) {
>    return create_function('$matches', "return modelReplacer($model,
> \$matches);");
> }
>
> /** The callback for preg_replace_callback. */
> function modelReplacer($model, $matches) {
>    // do the replacement...
> }
>

So effectively I want to create a new anonymous function wrapping
modelReplacer which has the $model parameter already set. The problem is
obviously that I can't put $model in the string.
Is there a better alternative approach for currying in PHP that will enable
me to bind an object to a parameter?

TIA,
--rob


On 9/4/07, Richard Heyes <[EMAIL PROTECTED]> wrote:
>
> > I have a function which is my callback for preg_replace_callback - and
> it
> > needs to be able to access a string and an object outside of itself.
> > When I call create_function I can insert the string, but without
> serializing
> > the object I can't figure out how to make it available to the function
> > without making it global, which seems nasty.
> >
> > I've tried 'currying' the function - creating a new function out of it
> with
> > the string and object parameters bound, but have the same problem - I
> can't
> > get the object into the function.
> > Can anyone point me towards a good solution? I guess I could also create
> a
> > class with the one function, but that seems a wee bit messy to me.
>
> It would be helpful if you could post a bare-bones example.
>
> --
> Richard Heyes
> +44 (0)800 0213 172
> http://www.websupportsolutions.co.uk
>
> Knowledge Base and HelpDesk software
> that can cut the cost of online support
>



-- 
Rob Desbois
Eml: [EMAIL PROTECTED]
Tel: 01452 760631
Mob: 07946 705987
"There's a whale there's a whale there's a whale fish" he cried, and the
whale was in full view.
...Then ooh welcome. Ahhh. Ooh mug welcome.

--- End Message ---

--- End Message ---
--- Begin Message ---
I have the following code and it doesn't behave properly but I can't find my
error. The code is designed to validate user login. When I pass in an
invalid email name to the checkLogin function it returns a result, not FALSE
as the documentation describes. I can SELECT * from the table being used and
read out all of the data so I know that the DB connection is valid and that
I can compose a valid query. I have looked and looked at this code and can
find no error, does anyone see an error here. When the check if (!$result)
fails i.e. even thought the email/password are not in the db a none zero
result is returned, the calls to mysql_fetch_assoc () return empty strings.
The only clue I may have is that when I call mysql_free_result($result) I
get a warning saying that $result is not a valid resource. I sure I'm doing
something stupid but I just can't see it. Any help would be great!

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>

<html xmlns="http://www.w3.org/1999/xhtml";>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<?php

            global $db;

                        

            $db = mysql_connect('localhost', 'xxxx', 'xxxx', 'xxxx'); 

            if (!$db) {

                        die("Unable to connect to database: ".
mysql_connect_error());

            }

            $selected = mysql_select_db("xxxx", $db) or die( "Unable to
select database");

            if (checkLogin([EMAIL PROTECTED]', '1')) {

                        echo "Success";

            } else {

                        echo "Failure";

            }

            if(checkLogin('duck', '2') )) {

                        echo "Success";

            } else {

                        echo "Failure";

            }

 

            function checkLogin($e, $p) {

                        $ans = 0;

                        $emailcheck = $e;

                        $passwdcheck = $p;

                        $result = 0;

                        $query = "SELECT * FROM maillist WHERE
email='$emailcheck' AND passwd='$passcheck'"; 

                        $result = mysql_query($query);

                        if (!$result) {

                                    echo "<h4>UserName is FALSE name is:
$e<h4>";

                                    echo "<h4>Password is FALSE name is:
$p<h4>";

                                    $ans = 0;

                        } else {

                                    $row = mysql_fetch_assoc($result);

                                    $em = $row['email'];

                                    $pw = $row['passwd'];

                                    echo "<p>Accepted ";

                                    echo "User $em ";

                                    echo "Password $pw</p>";

                                    $ans = 1;

                        }

                        return($ans);

            } //checkLogin

            mysql_free_result($result);

            mysql_close($db);

?>

</body>

</html>

 


--- End Message ---
--- Begin Message ---
2007. 09. 5, szerda keltezéssel 16.31-kor Brian Welter ezt írta:
> I have the following code and it doesn't behave properly but I can't find my
> error. The code is designed to validate user login. When I pass in an
> invalid email name to the checkLogin function it returns a result, not FALSE
> as the documentation describes. I can SELECT * from the table being used and
> read out all of the data so I know that the DB connection is valid and that
> I can compose a valid query. I have looked and looked at this code and can
> find no error, does anyone see an error here. When the check if (!$result)
> fails i.e. even thought the email/password are not in the db a none zero
> result is returned, the calls to mysql_fetch_assoc () return empty strings.
> The only clue I may have is that when I call mysql_free_result($result) I
> get a warning saying that $result is not a valid resource. I sure I'm doing
> something stupid but I just can't see it. Any help would be great!
> 

I don't know what is causing your problems but I put some comments below
in your code

>  
> 
> 
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> 
> <html xmlns="http://www.w3.org/1999/xhtml";>
> 
> <head>
> 
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> 
> <title>Untitled Document</title>
> 
> </head>
> 
>  
> 
> <body>
> 
> <?php
> 
>             global $db;
> 
>                         
> 
>             $db = mysql_connect('localhost', 'xxxx', 'xxxx', 'xxxx'); 
> 
>             if (!$db) {
> 
>                         die("Unable to connect to database: ".
> mysql_connect_error());
> 
>             }
> 
>             $selected = mysql_select_db("xxxx", $db) or die( "Unable to
> select database");
> 
>             if (checkLogin([EMAIL PROTECTED]', '1')) {
> 
>                         echo "Success";
> 
>             } else {
> 
>                         echo "Failure";
> 
>             }
> 
>             if(checkLogin('duck', '2') )) {
> 
>                         echo "Success";
> 
>             } else {
> 
>                         echo "Failure";
> 
>             }
> 
>  
> 
>             function checkLogin($e, $p) {
> 
>                         $ans = 0;
> 
>                         $emailcheck = $e;
> 
>                         $passwdcheck = $p;
> 
>                         $result = 0;
> 
>                         $query = "SELECT * FROM maillist WHERE
> email='$emailcheck' AND passwd='$passcheck'"; 

here you put $passcheck in the query which does not exist (you create
$passwdcheck above).
btw, why not call the parameters their real name from the start?
these 3 lines:
function checkLogin($e, $p) {
        $emailcheck = $e;
        $passwdcheck = $p;

are the same as:
function checkLogin($emailcheck, $passwdcheck) {

(I see later you use the variables $e and $p in the echo statements. I
suggest decide which to use and use only one - probably the longer names
would be better since they inform you about the variable. Imagine if you
see this code 3 years later, could you guess what is in $e? And could
you guess what is in $emailcheck?)

and you don't have to initialise $result to 0, because it will be
initialised to the mysql_query return value 2 lines later anyway

hope that helps
Zoltán Németh

> 
>                         $result = mysql_query($query);
> 
>                         if (!$result) {
> 
>                                     echo "<h4>UserName is FALSE name is:
> $e<h4>";
> 
>                                     echo "<h4>Password is FALSE name is:
> $p<h4>";
> 
>                                     $ans = 0;
> 
>                         } else {
> 
>                                     $row = mysql_fetch_assoc($result);
> 
>                                     $em = $row['email'];
> 
>                                     $pw = $row['passwd'];
> 
>                                     echo "<p>Accepted ";
> 
>                                     echo "User $em ";
> 
>                                     echo "Password $pw</p>";
> 
>                                     $ans = 1;
> 
>                         }
> 
>                         return($ans);
> 
>             } //checkLogin
> 
>             mysql_free_result($result);
> 
>             mysql_close($db);
> 
> ?>
> 
> </body>
> 
> </html>
> 
>  
> 

--- End Message ---
--- Begin Message ---
Brian Welter wrote:
I have the following code and it doesn't behave properly but I can't find my
error. The code is designed to validate user login. When I pass in an
invalid email name to the checkLogin function it returns a result, not FALSE
as the documentation describes. I can SELECT * from the table being used and
read out all of the data so I know that the DB connection is valid and that
I can compose a valid query. I have looked and looked at this code and can
find no error, does anyone see an error here. When the check if (!$result)
fails i.e. even thought the email/password are not in the db a none zero
result is returned, the calls to mysql_fetch_assoc () return empty strings.
The only clue I may have is that when I call mysql_free_result($result) I
get a warning saying that $result is not a valid resource. I sure I'm doing
something stupid but I just can't see it. Any help would be great!

As the documentation states, mysql_query will return false when it encounters an error. Not finding any matching rows is not an error. Use mysql_num_rows to check if any matching rows were returned.

I would also recommend that you enable notices in your php.ini as your code will cause at least 2 notices to be generated, both of which would have given you a clue as to where the problem lies.

-Stut

--
http://stut.net/

--- End Message ---

Reply via email to