简体   繁体   English

PDO查询不要转到表SQL

[英]PDO query don't go to table SQL

I got a problem with PDO... 我对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 大部分内容有效,但可以通过INSERT INTO account_lijst进行

It doesn't works... 它不起作用...

But i checked everything but i think everything is fine:S... 但是我检查了所有东西,但我认为一切都很好:S ...

Can someone help me with this code please? 有人可以帮我这个代码吗?

*EDIT SQL *编辑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: 检查您的代码,我猜(可能)由于您编写where子句的方式而在此行附近存在错误:

 $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!! 希望它麻木!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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