PHP, MySQL, PDO - Insert Into Not Working -


i have code:

<?php require_once 'dbconfig.php';  if(isset($_get['id'])) {     try {     $db = new pdo("mysql:host=$host;dbname=$dbname", $username, $password);     $db->setattribute(pdo::attr_errmode, pdo::errmode_exception);     $db->setattribute(pdo::attr_emulate_prepares, false);      $getsavedholidays = $db->prepare("insert tvinfo(id, imdbid, name, rating, genre1, genre2, year, plot, uploader, views, downloads, uploaddate, size, resolution, fps, audio) values (:id, :id, :id, :id, :id, :id, :id, :id, :id, :id, :id, :id, :id, :id, :id, :id)");     $getsavedholidays->setfetchmode(pdo::fetch_assoc);     $getsavedholidays->execute(array(':id' => $_get['id']));     $result = $getsavedholidays->fetchall();      if(!$result){         die('error: id not found');     }  } catch (pdoexception $e) {     print_r($e->errorinfo);     die(); }  foreach ($result $r) {     echo 'name: '.$r['name'].'<br>';     echo 'rating: '.$r['rating'].'<br>';     echo 'imdb id: '.$r['imdbid'].'<br>';     echo 'genre 1: '.$r['genre1'].'<br>';     echo 'genre 2: '.$r['genre2'].'<br>';     echo 'year: '.$r['year'].'<br>';     echo 'plot: '.$r['plot'].'<br>';     echo 'uploader: '.$r['uploader'].'<br>';     echo 'views: '.$r['views'].'<br>';     echo 'downloads: '.$r['downloads'].'<br>';     echo 'uploaded at: '.$r['uploaddate'].'<br>';     echo 'size: '.$r['size'].'<br>';     echo 'resoution: '.$r['rsolution'].'<br>';     echo 'fps: '.$r['fps'].'<br>';     echo 'audio: '.$r['audio'].'<br>'; }  }  ?> 

when go example.com/file.php?id=lel outputs: array ( [0] => hy093 ) , no error_logs. tables etc there.

this code works fine when use select query grab info , output when try inserting wont work. ideas?

you can set attr_emulate_prepares true:

$db->setattribute(pdo::attr_emulate_prepares, true); 

then allowed bind single time or have each time have in query

also rid of $result = $getsavedholidays->fetchall(); since inserting there nothing fetch

to check if value exist before inserting, can do:

$sql = 'select count(*) tvinfo imdbid = :id'; $stmt = $conn->prepare($sql); $stmt->execute(array(':id' => $_get['id']));  if($stmt->fetchcolumn()){ die('already exist');} 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -