Welcome Guest, Not a member yet? Register   Sign In
Problem with a While... double MySQL INSERT...
#1

[eluser]jbrozz[/eluser]
Hello,

I have a fantastic problem with my sql insert query!
The query is in the while condition, the code:
Code:
while($row = database::results($query, MYSQL_ASSOC))
                {
                    if($row['account_id'] == 1)
                    {
                        // tutto ok!
                        // inserisco l'offerta nel database e scalo all'utente
                        // i crediti giocati :)
                        $sql = "INSERT INTO bid_clicks            
                                    VALUES
                                    (
                                        ".input::sanitize(input::post('account_bid_id')).",
                                        ".input::escape_str(session::get_userdata('account_session')).",
                                        ".input::sanitize(input::post('account_bid_value')).",
                                        ".time()."
                                    )";
                                        
                        // eseguo la query di inserimento!
                        database::query($sql);
                        
                        // scalo all'utente i crediti relativi all'offerta
                        $sql = "UPDATE accounts
                                    SET accounts.account_credits = accounts.account_credits-".input::sanitize($results['bid_credits'])."
                                        WHERE accounts.account_hash = ".input::escape_str(session::get_userdata('account_session'))."
                                    LIMIT 1";

                        // eseguo la query di update
                        database::query($sql);
                        echo json_encode(array('success' => true, 'message' => 'Offerta di '.input::post('account_bid_value').' € eseguita!'));    
                        return true;
                    }
                    else
                    {
                        echo json_encode(array('success' => false, 'message' => 'Credito insufficiente! Ricaricalo per giocare!'));
                        return false;                
                    }

At end of execute... I have two identical records into db, but the cicle doesn't execute two times.
Sorry for english!

O_o
#2

[eluser]tonanbarbarian[/eluser]
what framework are you using for this because your code does not look like CI, it sort of looks like kohana, but i cant be sure because i have only glanced at kohana.

If it is not CI code then you should really post this to the appropriate framework site rather than here

as for what you do have if the query that is being retrieved in the where has 2 or even 10 records, that is how many times the loop will be run
#3

[eluser]jbrozz[/eluser]
[quote author="tonanbarbarian" date="1245907600"]what framework are you using for this because your code does not look like CI, it sort of looks like kohana, but i cant be sure because i have only glanced at kohana.

If it is not CI code then you should really post this to the appropriate framework site rather than here

as for what you do have if the query that is being retrieved in the where has 2 or even 10 records, that is how many times the loop will be run[/quote]

Hello, thanks for reply!

The loop runs one time! This is my framework based on CI and develop with PHP 5 Smile
It's a beta testing of new opensource framework!




Theme © iAndrew 2016 - Forum software by © MyBB