-1

I tried to add a section to IMPORT infos from a form into a db table and I get this error:

Fatal error: Call to a member function prepare() on a non-object in /srv/disk7/2173760/www/site.net/admin.php on line 79

and this is the code I tried to use:

<?php
            $pdo = new PDO('mysql:host=;dbname=', '', '');
            $sql = "SELECT * FROM games LIMIT 10";
            foreach ($pdo->query($sql) as $row) {
                              if(isset($_POST['insert']))
                              {        
                           $game_title=$_POST['gtitle']; 
                           $yt_id=$_POST['ytlink'];
                           $name=$_POST['gtitle'];
                           $source=$_POST['slink'];
                           $url=$_POST['keysl'];
                           $steam_id=$_POST['appid'];
                           $categories=$_POST['inlineRadioOptions'];
                           $query_ins="INSERT INTO tbl_games(ytlink,gtitle,slink,keysl,appid,keysleft) VALUES(:yt_id,:name,:source,:url,:steam_id,:categories)";
                           $stmt_query=$dbh->prepare($query_ins);
                           $games_ins=$stmt_query->execute(array(":yt_id"=>$ytlink,":name"=>$gtitle,":source"=>$slink,":url"=>$keysl,":steam_id"=>$appid,":categories"=>$keysleft));
                           if(!$games_ins)
                           {
                           $error=$stmt_query->errorInfo();
                           echo $error['2'];
                           }
                           }
        ?>

this is line 79:

$stmt_query=$dbh->prepare($query_ins);

I replaced with this and still don't working..

<?php
            $pdo = new PDO('mysql:host=;dbname=', '', '');
            $sql = "SELECT * FROM games LIMIT 10";
            foreach ($pdo->query($sql) as $row) {
                            $query = "INSERT INTO tbl_games(yt_id,name,url,source,keysleft,steam_id)".
                            "SELECT ytlink,gtitle,slink,keysl,appid FROM games LIMIT 10"

          ?>
J. Doe
  • 113
  • 1
  • 9

1 Answers1

0

You have to instantiate $dbh before use it, like you've done with $pdo.

Why don't you use the object $pdo from the second line instead?

Carlos Ost
  • 492
  • 7
  • 22