Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.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/0/email/3.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 insert.php在mysql中插入数据时出错_Php_Html - Fatal编程技术网

使用php insert.php在mysql中插入数据时出错

使用php insert.php在mysql中插入数据时出错,php,html,Php,Html,我在插入数据方面遇到了挑战。一切都检查出来了…即连接到数据库。数据不能只是插入。我正在使用本地主机xampp。 myinsert.php <?php $servername = "localhost"; $username = "root"; $password = "Maweutah2"; $dbname = "digital_content"; $link = mysqli_connect($servername, $username, $password, $dbname ); /

我在插入数据方面遇到了挑战。一切都检查出来了…即连接到数据库。数据不能只是插入。我正在使用本地主机xampp。 myinsert.php

<?php
$servername = "localhost";
$username = "root";
$password = "Maweutah2";
$dbname = "digital_content";
 $link = mysqli_connect($servername, $username, $password, $dbname );
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$ref = mysqli_real_escape_string($link, $_REQUEST['ref']);
$date = mysqli_real_escape_string($link, $_REQUEST['date']);
$name = mysqli_real_escape_string($link, $_REQUEST['name']);
$class = mysqli_real_escape_string($link, $_REQUEST['class']);
$serial = mysqli_real_escape_string($link, $_REQUEST['serial']);
$details = mysqli_real_escape_string($link, $_REQUEST['details']);
$remarks = mysqli_real_escape_string($link, $_REQUEST['remarks']);

// attempt insert query execution
$sql = "INSERT INTO laptop_repair (ref, name, class, serial, details, remark) VALUES ('$ref', '$date', '$name', '$class', '$serial', '$details', '$remarks')";
if(mysqli_query($link, $sql)){
    echo "<h2>Records added successfully<a href='laptop_repairs.php'>ENTER AGAIN</h2></a>.";
} else{
    echo "<h2>ERROR: TRY AGAIN <a href='db.php'>ENTER AGAIN</h2></a>";
}

// close connection
mysqli_close($link);
?>
更新此

$sql = "INSERT INTO laptop_repair (ref, date, name, class, serial, details, remark) VALUES ('$ref', '$date', '$name', '$class', '$serial', '$details', '$remarks')";

您将忘记插入日期值。您在查询中没有提到。

您收到的错误消息是什么?您所说的“但我的表中没有插入数据”是什么意思?
mysqli\u查询()是否成功?如果没有,请使用查找原因。我看到6个字段和7个值。您应该添加错误处理,并读取实际错误,例如告诉mysqli抛出异常。然后你会看到你试图在6个字段中插入7个值。你的脚本甚至有被使用的风险。是的,我已经纠正了它。我只能插入一行数据。任何其他尝试都是失败的。但是,与数据库的连接是成功的。
$sql = "INSERT INTO laptop_repair (ref, date, name, class, serial, details, remark) VALUES ('$ref', '$date', '$name', '$class', '$serial', '$details', '$remarks')";