简体   繁体   中英

PDO query don't go to table SQL

I got a problem with PDO...

I have this code:

                        <center>
            <?php

            /*
                $payid = $_GET["payid"];
                $data = mysql_connect('localhost','cheapacc_ross2','dsaikoepwq2312','cheapacc_account');
                mysql_select_db('cheapacc_account',$data);
                $pay1 = mysql_query("SELECT ID,Categorie,Naam,Email,md5_ID FROM acount_Betalingen WHERE md5_ID = '".$payid."' ");
                $pay = mysql_fetch_object($pay1); 
                if($pay){
                    echo 'betaling is gelukt';
                }else{
                    echo 'Oops jij liegt ons voor?? '.$pay->md5_ID .mysql_error();
                }
                */

                $flag=0;
                require_once '../../include/config.php';
                require_once '../../include/processes.php';
                $Login_Process = new Login_Process;
                $Login_Process->check_status($_SERVER['SCRIPT_NAME']);

                $type = base64_decode($_GET["t"]);
                $amount = (int)base64_decode($_GET["a"]);

                $host = "localhost";
                $username = "root";
                $password = "20101998";
                $dbname = "ross23";

                try
                {
                    $db = new PDO("mysql:host=" . $host . ";dbname=" . $dbname, $username, $password);
                }
                catch(PDOException $e)
                {
                    exit("Error database connection. E: " . $e);
                }

                $info = $_SESSION['info'];

                if(!isset($_GET["t"]) || !isset($_GET["a"]) || !isset($_GET["h"]) || sha1(md5($info)) != $_GET["h"])
                {
                    exit("1: FOUT! / You may not change the url, or you get a ip ban!");
                }

                if(isset($_GET["t"]) && isset($_GET["a"]) && isset($_GET["h"]) && sha1(md5($info)) == $_GET["h"])
                {
                    $q = $db->query("SELECT COUNT(*) FROM account_" . $type . " ");
                    $count = $q->fetchColumn();

                    if($count < $amount)
                    {
                        die("Er zijn te weinig accounts voor jouw betaling, meld dit aan de administrator!");
                    }

                    for($i = 0; $i < $amount; $i++)
                    {
              $flag=0;
                        $getid = $db->prepare("SELECT id FROM account_".$type." WHERE used = ?");
                        $getid->execute( array('0') );
                        $pid = $getid->fetch();

                        if($pid[0] == null)
                        {
                                    exit("Er zijn geen accounts over, meld dit aan de administrator!");
                        }


                        $id = $pid[0]; 

                        $stmt = $db->prepare("SELECT * FROM account_" . $type . " WHERE id = ? AND used = ?");
                        $stmt->execute( array($id, '0') );
                        $result = $stmt->fetch();

                        if(!$result)
                        {
                            exit("2: FOUT! / You may not change the url, or you get a ip ban.");
                        }

                        $userinfo = $db->prepare("SELECT userid FROM cw_users WHERE info = ?");
                        $userinfo->execute( array($info) );
                        $userinfo = $userinfo->fetch();


                        $sql = $db->prepare("INSERT INTO account_lijst SET user_id = ? WHERE account = ?");
                        $sql->execute(array($userinfo[0], $result));


                        $user_id = $_SESSION['userid'] ; 
            // query
            $sql = "INSERT INTO account_lijst (user_id,soort) VALUES (:user_id,:soort)";
            $q = $db->prepare($sql);
            $q->execute(array(':author'=>$user_id,
                              ':title'=>$type));






                        $account_info = explode(":", $result[1]);

                        $html = "Account Username: " . $account_info[0] . "<br />";
                        $html .= "Account Password : " . $account_info[1];
                        $html .= "<br /><br />";
                        $flag = 1;
                        if ($flag==1){
                        $sql = $db->prepare("UPDATE account_" . $type . " SET used = ? WHERE ID = ?");
                         $sql->execute( array("1", $id) );



                            echo $html;
                        }

                        echo 'test';  
                    }
                }

The most of the part works but by INSERT INTO account_lijst

It doesn't works...

But i checked everything but i think everything is fine:S...

Can someone help me with this code please?

*EDIT SQL

    CREATE TABLE IF NOT EXISTS `account_lijst` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
      `user_id` int(11) NOT NULL,
      `account` text NOT NULL,
      `date` text NOT NULL,
      `soort` text NOT NULL,
      PRIMARY KEY (`id`)
     ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

On your query :

$sql = $db->prepare("INSERT INTO account_lijst SET user_id = ? WHERE account = ?");
                    $sql->execute(array($userinfo[0], $result));

Try that instead :

$sql = $db->prepare("INSERT INTO account_lijst SET user_id = :user_id WHERE account = :account");
$sql->bindValue(':user_id', $userinfo['0']);
$sql->bindValue(':account', $result);
$sql->execute();

Should work perfectly if the parameters you gave are the good ones? If you it doesn't can you please dump the parameters used into the query and the table's structure so we can debug deeper? :)

Check your code i guess (probably) there is an error near of this line due to the way you wrote the where clause:

 $userinfo = $db->prepare("SELECT userid FROM cw_users WHERE info = ?");

Try this instead:

 $userinfo = $db->prepare("SELECT userid FROM cw_users WHERE info = ' ? ' ");

As well in your insert you should use simple apostrophe in ordert o execute that insert:

   $sql = $db->prepare("INSERT INTO account_lijst SET user_id = ? WHERE account = ?");

Hope it heps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM