Registration with PDO

Hello guys, ive got a problem on my script and i cant figure out a solution.
This is my script
[php] <?php
if($register) {
if (isset($_POST[‘username’])) {
$check_login = $account->prepare(“SELECT count(*) FROM account WHERE login = '”.$_POST[‘username’]."’");
$check_login->execute();
$check_login = $check_login->fetchColumn();

                                $check_email = $account->prepare("SELECT count(*) FROM account WHERE email = '".$_POST['email']."'");
                                $check_email->execute();
                                $check_email = $check_email->fetchColumn();
                               
                                if($check_login>0)
                                    print '<div class="headline">
                                                <center><font color="red">Nome utilizzato, non disponibile.</font></center>
                                            </div>';
                                else if($check_email>0)
                                    print '<div class="headline">
                                                <center><font color="red">Questa email è utilizzata da un altro account</br></br></font></center>
                                            </div>';
                                else {
                                    if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                                        if($_POST['pw'] == $_POST['repeat_pw']) {
                                           
                                            $hash = "*" . sha1(sha1($_POST['pw'], true));
                                            $password = strtoupper($hash);
                                           
                                            if($bonus)
                                                $expire = "20221218131717";
                                            else
                                                $expire = "0";
                                            $sql = "INSERT INTO account(login,
                                                        password,
                                                        social_id,
                                                        email,
                                                        create_time,
                                                        status,
                                                        gold_expire,
                                                        silver_expire,
                                                        safebox_expire,
                                                        autoloot_expire,
                                                        fish_mind_expire,
                                                        marriage_fast_expire,
                                                        money_drop_rate_expire) VALUES (
                                                        :login,
                                                        :password,
                                                        :social_id,
                                                        :email,
                                                        NOW(),
                                                        :status,
                                                        :gold_expire,
                                                        :silver_expire,
                                                        :safebox_expire,
                                                        :autoloot_expire,
                                                        :fish_mind_expire,
                                                        :marriage_fast_expire,
                                                        :money_drop_rate_expire)";
                                                                                     
                                           
                                            $stmt = $account->prepare($sql);                                     
                                            $stmt->bindParam(':login', $_POST['username'], PDO::PARAM_STR);      
                                            $stmt->bindParam(':password', $password, PDO::PARAM_STR);      
                                            $stmt->bindParam(':social_id', $_POST['delcode'], PDO::PARAM_STR);      
                                            $stmt->bindParam(':email', $_POST['email'], PDO::PARAM_STR);      
                                            $stmt->bindParam(':status', $status_register, PDO::PARAM_STR);      
                                           
                                            $stmt->bindParam(':gold_expire', $expire, PDO::PARAM_STR);
                                            $stmt->bindParam(':silver_expire', $expire, PDO::PARAM_STR);
                                            $stmt->bindParam(':safebox_expire', $expire, PDO::PARAM_STR);
                                            $stmt->bindParam(':autoloot_expire', $expire, PDO::PARAM_STR);
                                            $stmt->bindParam(':fish_mind_expire', $expire, PDO::PARAM_STR);
                                            $stmt->bindParam(':marriage_fast_expire', $expire, PDO::PARAM_STR);
                                            $stmt->bindParam(':money_drop_rate_expire', $expire, PDO::PARAM_STR);
                                           
                                            $stmt->execute();[/php]

But when i register the database (account.account) doesnt receive the data i input, what can i do to fix this? Thanks in advance

Turn on error reporting and you will have an answer.

Since i cant get to the php.ini file (Thanks to ovh) And in development mode it says that errorlog is on but it doesnt show/print nothing can you give me some kind of hint so i can make myself an idea?
Thanks in advance

You don’t need to get at the ini file. Put this at the top of your script.

error_reporting(-1);
ini_set(‘display_errors’, ‘1’);

I did but with no success, the page doesnt print me anything :’(

If that is your whole code, you are missing several { }

Where is $register supposed to come from?

Thanks for your time i really appreciated, so $Register is not used in the index.php so i guess i can delete that?
This is all my index.php, the other scripts are working just fine but the one i posted is not
http://pastebin.com/Peb7FFLh
You think deleting that if wich i think is useless and checking the {} will do the work? Thanks mate for the help

EDIT: Im thinkin on adding a check on that
if ($stmt->execute()) {
// it worked print registration success
} else {
// it didn’t work
}

EDIT2: I found out that $Register is on another file it basically checks if registrations are ENABLED or DISABLED and hide/shows the forms

EDIT3: When i missed a } the website actually printed me the error so why adding that line it doesnt show me anything? Bad coded PDO script?

$stmt->rowCount() will give the affected rows for UPDATE, INSERT, and DELETE queries.

One glaring issue, that doesn’t have to do with what you present is this:
[php]$check_login = $account->prepare(“SELECT count(*) FROM account WHERE login = '”.$_POST[‘username’]."’");[/php]

I dont think i understood what you did say, can you reformulate the sentence please?
English is not my main language im sorry…
By the way i checkd the rowCount function you adviced me, should i do this?
[php]
$count = $sql->rowCount();
print(“Affected $count rows.\n”);[/php]
to debug it?

Using rowCount isn’t just for debugging. You can also use it for the if statement on an insert. If it == 1 it inserted, if not the insert failed.

The sentence was showing that you are using a prepared statement, but still dropping the variable into the statement, thereby making the prepared statement useless.

Sponsor our Newsletter | Privacy Policy | Terms of Service