New topic: 

Can someone help me to get this working correctly?

<http://forums.realsoftware.com/viewtopic.php?t=30437>

       Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic         Author  
Message       ikkyino           Post subject: Can someone help me to get this 
working correctly?Posted: Sun Oct 11, 2009 7:00 pm                        
Joined: Sun Nov 02, 2008 7:39 pm
Posts: 9              This set of code is for registering a new user to a mysql 
database..
yet for some reason rs keeps returning 'nil' which allows you to create the 
username even if it exists..
I have a similar code (for the login) which works just fine? I don't see why 
this would return nil, while elsewhere in the program it works perfectly fine?


Code:sql = "SELECT * FROM users WHERE name = '" + name + "'"
if datab.Connect() then
  rs = dataB.SQLSelect(sql)
  if rs <> nil then
  cSSLsock(id).Write "~101~no~/101~" // usernames already exists.. no dice
  elseif rs = nil then
  icdb.dbSU("execute~!~INSERT INTO users (name, password, email) VALUES ('" + 
trim(name) +"', '" + trim(password) + "', '" + trim(email) + "')")// name does 
not exsist... goes ahead and creates new user
  cSSLsock(id).Write "~101~yes~/101~"// sends that username was created
  end if
end if
   
                            Top                timhare           Post subject: 
Re: Can someone help me to get this working correctly?Posted: Sun Oct 11, 2009 
8:33 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6525
Location: Portland, OR  USA              If rs returns as nil, it means there 
was an ERROR, not that it wasn't found.  You shouldn't try to add the user, 
because it, too, may fail.  Check datab.ErrorMessage to see what went wrong.

Tim   
                            Top               DaveS           Post subject: Re: 
Can someone help me to get this working correctly?Posted: Sun Oct 11, 2009 9:17 
pm                               
Joined: Sun Aug 05, 2007 10:46 am
Posts: 1644
Location: San Diego, CA              If you want to see if a user exists, and 
be sure you will get a result [barring a database error of course].... try this

Code:
SELECT count(*) as cnt FROM users where name='"+name+"'"
  


if rs.fields('cnt').integervalue=0 then // username did not exists [1 if it 
did]     
_________________
Dave Sisemore
MacPro, OSX 10.5.8 RB2009r2  
                            Top               ikkyino           Post subject: 
Re: Can someone help me to get this working correctly?Posted: Sun Oct 11, 2009 
11:21 pm                        
Joined: Sun Nov 02, 2008 7:39 pm
Posts: 9              timhare wrote:If rs returns as nil, it means there was an 
ERROR, not that it wasn't found.  You shouldn't try to add the user, because 
it, too, may fail.  Check datab.ErrorMessage to see what went wrong.

Tim
Well it's returning error "MySQL server has gone away"
And it creates the user successfully anyways (but I think I know why it does 
that.. It's the way I have it set-up)...
I have a couple of questions about Databases and Recordsets and such...

First, I create the database/establish the connection in a module.. Is that 
okay?.. (have, dataB as MySQLCommunityServer) (then a method which sets the 
username/pass/port etc.. which executes on start)
Code:datab = new MySQLCommunityServer
datab.UserName = "username"
datab.Password = "pw"
dataB.host = "host"
datab.port = 3306
datab.DatabaseName = "databasename"

So can I just call datab.sqlselect(sql) anywhere? or is there a proper way? do 
i need to redo datab = new mysqlcommunityserver?


Also, What causes "MySQL server to go away?"   
                            Top                ikkyino           Post subject: 
Re: Can someone help me to get this working correctly?Posted: Mon Oct 12, 2009 
1:40 am                        
Joined: Sun Nov 02, 2008 7:39 pm
Posts: 9              and since i'm noobish.. a better explanation on how to 
use recordsets and how they work  cuz i fail at those obviously...   
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to