Php 在mysql中使用GET插入数据

Php 在mysql中使用GET插入数据,php,mysql,database,insert,get,Php,Mysql,Database,Insert,Get,我想在表“test”中插入数据,但在mysql中插入数据时遇到问题 我的数据库名mytesttable 该代码使用GET插入数据: <?php include_once('confi.php'); echo "hi there this is a test"; //Get the variables here $username= isset($_GET['username']) ? mysql_real_escape_string($_GET['username']) : ""; $

我想在表“test”中插入数据,但在mysql中插入数据时遇到问题 我的数据库名mytesttable

该代码使用GET插入数据:

<?php
include_once('confi.php');

echo "hi there this is a test";
//Get the variables here
$username= isset($_GET['username']) ? mysql_real_escape_string($_GET['username']) :  "";
$email = isset($_GET['email']) ? mysql_real_escape_string($_GET['email']) :  "";
$password = isset($_GET['password']) ? mysql_real_escape_string($_GET['password']) :  "";
$insertstatement = 'INSERT INTO `test`(`id`,`username`,`email`,`password`) VAlUES (NULL,"'.$username.'","'.$email.'","'.$password.'")';

$query123 = mysql_query($insertstatement) or trigger_error(mysql_error()." ".$insertstatement);

echo "$query123";


?>
使用


学习


[注意:]

您遇到了什么错误?您不能混合使用mysql和mysqli方法。@aynber您能告诉我如何解决这个问题吗?请对所有内容使用mysqli函数,而不是mysql。我强烈建议您利用mysqli准备好的语句来防止SQL注入。
<?php header('Access-Control-Allow-Origin: *'); ?>
<?php header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); ?>
<?php header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT'); ?>

<?php

    $con = mysqli_connect("localhost","root","root","mytesttable","8889");

    if(mysqli_connect_errno())
    {
        echo "Error occured while connecting with database ".mysqli_connect_errno();
    }


?>
<?php
include_once('confi.php');

$username= isset($_GET['username']) ? mysql_real_escape_string($_GET['username']) :  "";
$email = isset($_GET['email']) ? mysql_real_escape_string($_GET['email']) :  "";
$password = isset($_GET['password']) ? mysql_real_escape_string($_GET['password']) :  "";

$stmt = mysqli_prepare($con, "INSERT INTO `test`(`username`,`email`,`password`) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sss', $username, $email, $password);

$query123 = mysqli_stmt_execute($stmt);

?>