Re: [PHP] Checking database for a value

2002-04-20 Thread Jason Wong

On Sunday 21 April 2002 01:10, Jason Wong wrote:
> On Sunday 21 April 2002 00:55, Denis L. Menezes wrote:
> > hello friends,
> >
> > I am looking into 4 books in front of me but somehow cannot find the
> > following :
> >
> > I have a field userid which the user fills in at registration. Before
> > entering the data into the database, I want to check if the userid exists
> > in the database.
> >
> > Can someone tell me the name of the function I must use, I will look for
> > the rest in the php dictionary.
>
> AFAIK there are no built-in functions to do that. You need to run a query
> like "SELECT userid FROM table" then see whether any rows are returned. If
> you use this often you can wrap it up in a function.

That of course should be:

  "SELECT userid FROM table WHERE userid='user_id_to_check'"

I better get some sleep :)

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Delta: We never make the same mistake three times.   -- David Letterman
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Checking database for a value

2002-04-20 Thread Jason Wong

On Sunday 21 April 2002 00:55, Denis L. Menezes wrote:
> hello friends,
>
> I am looking into 4 books in front of me but somehow cannot find the
> following :
>
> I have a field userid which the user fills in at registration. Before
> entering the data into the database, I want to check if the userid exists
> in the database.
>
> Can someone tell me the name of the function I must use, I will look for
> the rest in the php dictionary.

AFAIK there are no built-in functions to do that. You need to run a query 
like "SELECT userid FROM table" then see whether any rows are returned. If 
you use this often you can wrap it up in a function.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
I'm reporting for duty as a modern person.  I want to do the Latin Hustle now!
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Checking database for a value

2002-04-20 Thread Miguel Cruz

On Sun, 21 Apr 2002, Denis L. Menezes wrote:
> I am looking into 4 books in front of me but somehow cannot find the
> following :
> 
> I have a field userid which the user fills in at registration. Before
> entering the data into the database, I want to check if the userid exists in
> the database.
> 
> Can someone tell me the name of the function I must use, I will look for the
> rest in the php dictionary.

Say you're using MySQL...

  $userid = 'bob';

  $sql = "select userid from user where userid='$userid'";
  $st = mysql_query($sql);
  if (mysql_num_rows($st))
  {
print "UserID $userid already in use.";
  }
  else
  {
print 'Now adding you to the database...';
// ...
  }

miguel


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Checking database for a value

2002-04-20 Thread Intruder

DLM> I have a field userid which the user fills in at registration. Before
DLM> entering the data into the database, I want to check if the userid exists in
DLM> the database.


You have to SELECT that user from the table you store your users:
SELECT userid, name , etc FROM table WHERE userid='$your_id'
if *_num_rows() > 0 then he is already in, otherwise you can add him:
INSERT . INTO table 

Enjoy!


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php