TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-23-2007, 12:54 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default register function

What's wrong with it? :S:S

php Code:
public function user_register($user_name, $user_pass, $user_email, $user_firstname, $user_surname,
                                        $user_country, $user_location, $user_age, $user_access) {
           
            $sql = sprintf("    INSERT INTO
                                    `%s`
                                SET
                                    `%s` = '%s',
                                    `%s` = '%s',
                                    `%s` = '%s',
                                    `%s` = '%s',
                                    `%s` = '%d',
                                    `%s` = '%s',
                                    `%s` = '%s',
                                    `%s` = '%s',
                                    `%s` = '%s,
                                    `%s` = '%s'"
,
                                   
                                    $this->db->table['users'],
                                    $this->db->col['user_name'],
                                    $user_name,
                                    $this->db->col['user_pass'],
                                    md5($user_pass),
                                    $this->db->col['user_email'],
                                    $user_email,
                                    $this->db->col['user_firstname'],
                                    $user_firstname,
                                    $this->db->col['user_access'],
                                    $user_access,
                                    $this->db->col['user_surname'],
                                    $user_surname,
                                    $this->db->col['user_country'],
                                    $user_country,
                                    $this->db->col['user_location'],
                                    $user_location,
                                    $this->db->col['user_registered'],
                                    $this->now(),
                                    $this->db->col['user_age'],
                                    $user_age);
                                   
            $query = $this->db->query($sql);
           
            if(!$query) {
               
                return false;
               
            }
           
            return true;
           
        }

php Code:
if($error == 0) {
               
                if($tanaxia['user']->user_register($user_name, $user_pass, $user_email, $user_firstname, $user_surname,
                                                $user_country, $user_location, $user_age, '0')) {
                                                       
                   
                    echo 'Successfully registered!';                               
                                                       
                }
               
                else {
                   
                    echo '<font color="red">Something went wrong!</font><br />';
                   
                }
               
            }

Gives me "Something went wrong!" all the time I try to register :S
Tanax is offline  
Reply With Quote
Old 11-23-2007, 01:17 PM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Try changing:

PHP Code:
  if(!$query) { 
to

PHP Code:
 if (!mysql_affected_rows()) 
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 11-23-2007, 01:42 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea, it said "Successfully registered!", but when I check the database, the table is empty =//
Tanax is offline  
Reply With Quote
Old 11-23-2007, 01:53 PM   #4 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Oops, I made an error. Remove the ! from the condition.

PHP Code:
 if (!mysql_affected_rows()) 
to

PHP Code:
 if (mysql_affected_rows()) 
Although going off your last message, this will still fail. This leads me to believe that the problem is actually in the query.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote
Old 11-23-2007, 01:56 PM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The SQL query is malformed. `%s` = '%s, is missing a single quotation mark before the comma. You really, really need some form of error reporting -- I can't imagine posting every little problem here being an efficient solution to your typing mistakes.
Salathe is offline  
Reply With Quote
Old 11-23-2007, 02:10 PM   #6 (permalink)
Super Moderator
Advanced Programmer 
 
bluesaga's Avatar
 
Join Date: Sep 2007
Posts: 165
Thanks: 0
bluesaga is on a distinguished road
Default

Also, if you are going to the trouble of getting each column name, it would be much easier to read and less coding if you make a function to do all the above for you, and you make an array to populate the query....
__________________
Halo 3 Cheats
bluesaga is offline  
Reply With Quote
Old 11-23-2007, 02:10 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

This will give you some nice feedback on the syntax errors:

php Code:
$query = $this->db->query($sql) or die(mysql_error());
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-23-2007, 02:39 PM   #8 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Yea, I have no idea what you talk about bluesaga :P
Thanks salathe!

I also took wildhoneys advice, and after I fixed the thing that salathe pointed out, it gave me this:

Code:
Unknown column 'user_name' in 'field list'
Tanax is offline  
Reply With Quote
Old 11-23-2007, 02:50 PM   #9 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 12
Thanks: 0
DarkPrince11 is on a distinguished road
Default

That means that there is no user_name column in the table. :)
Send a message via AIM to DarkPrince11 Send a message via MSN to DarkPrince11
DarkPrince11 is offline  
Reply With Quote
Old 11-23-2007, 03:28 PM   #10 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default



:S:S:S

There is a user_name column in the table =//
Tanax is offline  
Reply With Quote
Old 11-23-2007, 03:48 PM   #11 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

Are you sure you're working on the right db ?
Are you sure of the content of your hashtable attribute "col" ?

solution of this kind of problem is often an oblivion :)
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 11-23-2007, 04:44 PM   #12 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

LOOL

Yea, rofl.. fixed it ;P
Thanks!
Tanax is offline  
Reply With Quote
Old 11-25-2007, 12:42 AM   #13 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Let me guess, wrong database :) ?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-25-2007, 10:21 AM   #14 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

hahha, yeaaa, lol ;)

I'm such a fool :p
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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


All times are GMT. The time now is 08:25 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design