Php 为什么MySQL会两次显示同一列?

Php 为什么MySQL会两次显示同一列?,php,mysql,database,Php,Mysql,Database,大家好{body]! 我有一个简单的“members”表,通常使用下面的函数向其中添加行。 问题是,当我调用read函数时,它会将每个列返回给我两次。如下所示: 最奇怪的是,除了“phone”之外,所有列都是正确的,它返回的是“1”,而不是空字符串 有人能帮我吗 以下是读取函数: function db_read($columnToRead, $table, $targetColumn, $targetValue) { //connecting to database i

大家好{body]! 我有一个简单的“members”表,通常使用下面的函数向其中添加行。

问题是,当我调用read函数时,它会将每个列返回给我两次。如下所示:

最奇怪的是,除了“phone”之外,所有列都是正确的,它返回的是“1”,而不是空字符串

有人能帮我吗

以下是读取函数:

function db_read($columnToRead, $table, $targetColumn, $targetValue) {

    //connecting to database
    include('dbConnection.php');
    
    //reading data
    $result = $tilelli->prepare('SELECT '.$columnToRead.' FROM '.$table.' WHERE '.$targetColumn.' = ? LIMIT 1');
    if ($result->execute(array($targetValue))) {
        return $result->fetch();
    } else {
        return "Accès à la base de données refusé!";
    }
}
//inserting a profile info
function info($svg, $text, $buttonHref, $buttonLabel, $rounded = false, $previewable = false, $notif = "") {
    $style = "";
    $class = "";
    $notification = '<span class="notifCounter">'.$notif.'</span>';
    if ($rounded)
        $style = 'style="border-radius: 50%;"';
    if ($previewable)
        $class = ' previewable';
    echo    '<div class="info">
                <p class="info_icon_container">
                    <img src="'.$svg.'" class="info_icon'.$class.'" '.$style.' />
                </p>
                <p class="info_text">
                    '.$text.'
                </p>
                <p class="info_alter" onclick="window.location=\''.$buttonHref.'\';">
                    '.$buttonLabel.$notification.'
                </p>
            </div>';
}
下面是调用方法:

//reading member
$member = db_read("*", "members", "link", $_SESSION["member"]["link"]);
print_r($member);
exit;
@博伊基费迪南德斯

是的,当我打印($member)时,它会正确显示手机,但请查看网页:

以下是“info()”函数:

function db_read($columnToRead, $table, $targetColumn, $targetValue) {

    //connecting to database
    include('dbConnection.php');
    
    //reading data
    $result = $tilelli->prepare('SELECT '.$columnToRead.' FROM '.$table.' WHERE '.$targetColumn.' = ? LIMIT 1');
    if ($result->execute(array($targetValue))) {
        return $result->fetch();
    } else {
        return "Accès à la base de données refusé!";
    }
}
//inserting a profile info
function info($svg, $text, $buttonHref, $buttonLabel, $rounded = false, $previewable = false, $notif = "") {
    $style = "";
    $class = "";
    $notification = '<span class="notifCounter">'.$notif.'</span>';
    if ($rounded)
        $style = 'style="border-radius: 50%;"';
    if ($previewable)
        $class = ' previewable';
    echo    '<div class="info">
                <p class="info_icon_container">
                    <img src="'.$svg.'" class="info_icon'.$class.'" '.$style.' />
                </p>
                <p class="info_text">
                    '.$text.'
                </p>
                <p class="info_alter" onclick="window.location=\''.$buttonHref.'\';">
                    '.$buttonLabel.$notification.'
                </p>
            </div>';
}
//插入配置文件信息
函数信息($svg、$text、$buttonHref、$buttonLabel、$rounded=false、$previewable=false、$notif=”“){
$style=“”;
$class=“”;
$notification=''.$notif';
如果(四舍五入)
$style='style=“边界半径:50%;”;
如果($可预览)
$class='previewable';
回声'

“.$text。”

“.$buttonLabel.$notification”

'; }
对不起,朋友们,这是一个愚蠢的打字错误。我在php代码中用(!)代替(!=)

$phone = "Aucun numéro de téléphone";
if ($member["phone"] =! "")
    $phone = $member["phone"];

只将结果作为关联或索引进行抓取…而不是两者。“PDO::FETCH_both(默认值):返回一个数组,该数组按结果集中返回的列名和0索引列编号进行索引”(您的代码是sql注入的天堂。我很确定,即使是php也能够准备/参数绑定).string concat+未删除的密码。很好combination@IncredibleHat谢谢你,兄弟,你在第一个“问题”上启发了我,但它仍然是最奇怪的:为什么“电话”column返回1而不是空字符串?@MichaelHauptmann我知道我的朋友,我正在开发阶段,稍后我会调整安全问题…什么是“phone”列返回1而不是空字符串?从您的图像中可以看到,phone的值为“0557190308”,在您的php代码中,string是string,
$member的结果是什么[“phone”]
,是1吗?还是'0557190308'?我已经有一段时间没有使用php了,你能试试使用
!=
?我不确定
=!
是否与
!=
@BoykeFerdinandes Ooh la la>做了同样的事情!这是一个简单的打字错误:我把(!)放在(!=)而不是(!=)谢谢你,我的朋友,你指给我。很高兴能帮上忙。