插入数据库之前的Echo var

时间:2017-02-20 13:26:26

标签: php

在将其放入数据库之前是否可以显示变量用户名?回声,警报,控制台或什么?我想在INSERT

之前检查$ username中的内容
 <?php

    require_once 'connect.php';

    $data = json_decode(file_get_contents("php://input"));

    $username = mysqli_real_escape_string($connect, $data->username);


    $query = "INSERT into tablename (username) VALUES ('$username')";

    mysqli_query($connect, $query);
    echo true;
    ?>

2 个答案:

答案 0 :(得分:0)

试试这个

$username = mysqli_real_escape_string($connect, $data->username);

 if($username)
 {
  echo $username;

$query = "INSERT into tablename (username) VALUES ('$username')";

mysqli_query($connect, $query);


}

答案 1 :(得分:0)

<?php

    require_once 'connect.php';

    $data = json_decode(file_get_contents("php://input"));

    $username = mysqli_real_escape_string($connect, $data->username);


    $query = "INSERT into tablename (username) VALUES ('$username')";


    echo "<script>alert('".$username."')</script>";

    mysqli_query($connect, $query);

    echo true;
    ?>