mysqli_real_escape_string未定义的索引

时间:2019-07-18 00:21:52

标签: php

我得到这些错误。代码是否错误?

注意:未定义索引:第15行的C:\ xampp \ htdocs \ se \ submit.php中的ID

注意:未定义的索引:第16行的C:\ xampp \ htdocs \ se \ submit.php中的名称 记录添加成功。

第15和16行是$ id = mysqli_real_escape_string($ link,$ _POST ['id']);     $ name = mysqli_real_escape_string($ link,$ _POST ['name']);分别。

/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */

$link = mysqli_connect("localhost", "root", "", "se");

// Check connection

if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$id = mysqli_real_escape_string($link, $_POST['id']);
$name = mysqli_real_escape_string($link, $_POST['name']);


// attempt insert query execution
$sql = "INSERT INTO blankdatabase (id, name) VALUES ('$id', '$name')";

if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// close connection
mysqli_close($link);

?>

0 个答案:

没有答案