PDO data not insert into database no error -
$query2="insert `articles` set article_title=:article,user_name=:user,post_id=:postid article_content=:articlecontent,article_rank=:rank,add_date=:date,article_100img=:article_100,articl e_200img=:article_200,article_400img=:article_400,artcle_600img=:article_600,article_slug=:slug"; $stmt=$db->prepare($query2); $stmt->bindparam(':article',$article_title); $stmt->bindparam(':articlecontent',$article_desc); $stmt->bindparam(':rank',$rank); $stmt->bindparam(':date',$date); $stmt->bindparam(':article_100',$x100img); $stmt->bindparam(':article_200',$x200img); $stmt->bindparam(':article_400',$x400img); $stmt->bindparam(':article_600',$x250img); $stmt->bindparam(':slug',$slug); $stmt->bindparam(':user',$name); $stmt->bindparam(':postid',$id); $stmt->execute();
i don't know problem of code..so please me.
to able see database errors, 1 have set pdo errmode exceptions. exceptions better regular errors in many ways: contains stack trace, can caught using try..catch or handled using dedicated error handler. , unhandled, act regular php errors providing important information, following site-wide error reporting settings.
note setting mode connection option let pdo throw exceptions on connection errors too, important.
so, here example creating pdo connection right way:
$dsn = "mysql:host=$host;dbname=$db;charset=utf8"; $opt = array( pdo::attr_errmode => pdo::errmode_exception, // other options ); $pdo = new pdo($dsn, $user, $pass, $opt);
connecting way, notified of database errors, occurred during query execution. note have able see php errors in general. on live site have peek error logs, so, settings have be
error_reporting(e_all); ini_set('display_errors',0); ini_set('log_errors',1);
while on local development server it's ok make errors on screen:
error_reporting(e_all); ini_set('display_errors',1);
and of course should never ever use error suppression operator (@
) in front of pdo statements.
also, due many bad examples telling wrap every pdo statement try..catch
block, have make distinct note:
do not use try..catch operator echo error message. uncaught exception excellent purpose, act same way other php errors - so, can define behavior using site-wide settings - so, you have error message without useless code. while unconditionally echoed error message may reveal sensitive information potential attacker, yet confuse honest visitor.
- a custom exception handler added later, not required. new users, recommended use unhandled exceptions, extremely informative, helpful , secure.
- use
try..catch
if going handle error - say, rollback transaction.
also, find article_xxx
fields quite useless. can't make these image names computational
? say, article id = 100500 100 image 100500_100.jpg?
Comments
Post a Comment