Wednesday, 15 September 2010

php - Can't INSERT into mysql via PDO -



php - Can't INSERT into mysql via PDO -

i've been banging head against php insert code lastly day or so. can't seem find problem , persists after 2 finish re-do's of code. problem pretty straightforward, won't insert anything, , i've cutting downwards on possibilities simple straight inputting values variables rather using obtain them html via js. maybe on here can spot going on. know pdo working though, because able obtain info mysql table.

<?php $tbl = 'transactions'; $acc = 'blah1'; $date = '2014-07-01'; $cp = 'counterparty'; $ctg = 'category'; $dbt = 1.00; $crd = 0.00; $user = "root"; $pass = #######; // note: password in file on side. seek { $con = new pdo("mysql:host=localhost;dbname=budget;charset=utf8",$user,$pass); $con -> setattribute(pdo::attr_errmode, pdo::errmode_exception); } grab (pdoexception $e) { echo 'error: ' . $e->getmessage(); } $sql = $con -> prepare("insert transactions values (:account, :date, :counterparty, :category, :debit, :credit)"); $sql -> bindvalue(':account', $acc, pdo::param_str); $sql -> bindvalue(':date', $date, pdo::param_str); $sql -> bindvalue(':counterparty', $cp, pdo::param_str); $sql -> bindvalue(':category', $ctg, pdo::param_str); $sql -> bindvalue(':debit', strval($dbt), pdo::param_str); $sql -> bindvalue(':credit', strval($crd), pdo::param_str); $sql -> execute(); $dbh = null; ?>

any help appreciated. thanks.

i answered in comments of post, i'm gonna post reply more visible:

well code works now, added js: xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) {}} in effort see going on try-catch blocks, , code started work. i'm not sure understand why fixed problem? care explain.

php mysql web pdo

No comments:

Post a Comment