TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   register function (http://www.talkphp.com/advanced-php-programming/1512-register-function.html)

Tanax 11-23-2007 12:54 PM

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

Karl 11-23-2007 01:17 PM

Try changing:

PHP Code:

  if(!$query) { 

to

PHP Code:

 if (!mysql_affected_rows()) 


Tanax 11-23-2007 01:42 PM

Yea, it said "Successfully registered!", but when I check the database, the table is empty =//

Karl 11-23-2007 01:53 PM

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.

Salathe 11-23-2007 01:56 PM

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.

bluesaga 11-23-2007 02:10 PM

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....

Wildhoney 11-23-2007 02:10 PM

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

php Code:
$query = $this->db->query($sql) or die(mysql_error());

Tanax 11-23-2007 02:39 PM

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'

DarkPrince11 11-23-2007 02:50 PM

That means that there is no user_name column in the table. :)

Tanax 11-23-2007 03:28 PM



:S:S:S

There is a user_name column in the table =//

Gibou 11-23-2007 03:48 PM

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 :)

Tanax 11-23-2007 04:44 PM

LOOL

Yea, rofl.. fixed it ;P
Thanks!

Wildhoney 11-25-2007 12:42 AM

Let me guess, wrong database :) ?

Tanax 11-25-2007 10:21 AM

hahha, yeaaa, lol ;)

I'm such a fool :p


All times are GMT. The time now is 05:46 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0