Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

PHP PDO Binded variables empty?

  • 22-02-2017 06:17PM
    #1
    Closed Accounts Posts: 1,747 ✭✭✭


    I'm trying to insert some values into a table and for some reason when binding my named parameters all I get are empty strings.

    [PHP]
    $conn = 'mysql:host=' . $hn . ';dbname=' . $db . '';
    $user = $un;
    $pass = $pw;

    $PDO = new PDO($conn, $user, $pass);
    $PDO->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

    $STH = $PDO->prepare("INSERT INTO table (reason_id, account_no, amount, created_at, company_id, user_id)
    VALUES (':reason', ':accref', ':amount', ':date', ':company', ':user')");

    $company = sanitizeString($_POST);
    $reason = sanitizeString($_POST);
    $accref = sanitizeString($_POST);
    $amount = sanitizeString(number_format(round($_POST, 2), 2, '.', ''));
    $date = sanitizeString(date('Y-m-d H:i:s'));
    $user = sanitizeString($_SESSION);

    $STH->bindValue(':reason', $reason, PDO::PARAM_INT);
    $STH->bindValue(':accref', $accref, PDO::PARAM_STR);
    $STH->bindValue(':amount', $amount, PDO::PARAM_STR);
    $STH->bindValue(':date', $date, PDO::PARAM_STR);
    $STH->bindValue(':company', $company, PDO::PARAM_INT);
    $STH->bindValue(':user', $user, PDO::PARAM_INT);
    $result = $STH->execute();

    if ($result) {
    echo 1;
    }[/PHP]

    In the case of :accref, the string ":accref" is inserted into the table.

    I just echo the sanitized variables I can see that they are there!

    Anyone any ideas?

    Thanks.


Comments

  • Closed Accounts Posts: 1,747 ✭✭✭Pelvis


    Never mind. I am an idiot. :)

    Spoiler
    remove single quotes from query


Advertisement