Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP没有正确执行_Php_Mysql_Pdo - Fatal编程技术网

PHP没有正确执行

PHP没有正确执行,php,mysql,pdo,Php,Mysql,Pdo,以下代码不起作用,调用php页面时,echo字符串为空字符串 但是,当我删除检查用户名是否已经存在的部分时,代码按预期工作 为什么会这样 <?php $db = new PDO('mysql:dbname=tipcc;host=localhost;charset=utf8', 'root', 'plsdonthack'); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO:

以下代码不起作用,调用php页面时,
echo
字符串为空字符串

但是,当我删除检查用户名是否已经存在的部分时,代码按预期工作

为什么会这样

<?php

$db = new PDO('mysql:dbname=tipcc;host=localhost;charset=utf8', 'root', 'plsdonthack');

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// This Part Is Causing Some Problem

$flag=0;
$temp = $_GET[username];
$stmt2 = $db->prepare ("SELECT * FROM userinfo WHERE USERNAME=:username2)");
$stmt2->bindParam (':username2',$temp,PDO::PARAM_STR);

$stmt2->execute ();

// Till Here.

if ($stmt2->rowCount () > 0 )
{
    $flag=1;
}

if ($flag == 0)
{
 // This Part Works Fine

    $stmt=$db->prepare ("INSERT INTO userinfo (NAME,IDNO,USERNAME,PASSWORD)
    VALUES
    (:name,:idno,:username,:password)");

    $stmt->bindParam (':name',$_GET[name], PDO::PARAM_STR);
    $stmt->bindParam (':idno',$_GET[idno], PDO::PARAM_STR);
    $stmt->bindParam (':username',$_GET[username], PDO::PARAM_STR);
    $stmt->bindParam (':password',$_GET[password], PDO::PARAM_STR);

    if ($stmt->execute () == 1 )
        {
            echo "Registered Sucessfully...!! Goto Contests and Code..!";

        }
        else
        {
            echo "Not Registered Due To Some Internal Error....Contact Rohith R";
        }
  // Till Here
}

else
{
    echo "Username Already Exists....Choose Another One";
}



?>

您的SQL代码有错误

SELECT * FROM userinfo WHERE USERNAME=:username2)
删除语句末尾的结束括号


您的代码引发异常,但您没有看到异常,因为PHP配置中关闭了参数
display\u error

尝试将代码放入Try/catch块:

try{

// your queries here

}catch(PDOException $Exception){
    echo $Exception->getMessage();
}

您可以在看到或记录另一个异常后引发它。

$temp=$\u GET[username]您忘记引用密钥:
$temp=$\u GET['username']是…谢谢回答将被接受。。。!!