我有错误 当我填写表格并单击提交 结果是错误“Data Gagal Di tambahkan” 这里是代码
<?php
include 'koneksi/koneksi.php';
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$nis = $_POST['nis'];
$nama = $_POST['nama'];
$kelas = $_POST['kelas'];
$nilai_ulangan_teori = $_POST['nilai_ulangan_teori'];
$nilai_ulangan_praktek = $_POST['nilai_ulangan_praktek'];
$sql = "INSERT INTO t_siswa VALUES ('$nis',
'$nama',
'$kelas',
'$nilai_ulangan_teori',
'$nilai_ulangan_praktek'
)";
$nilai ="($nilai_ulangan_teori + $nilai_ulangan_praktek)/2";
if (mysql_query($sql)){
header("location:index.php");
} else {
echo'<script type="text/javascript">alert("Data gagal ditambahkan");</script>';
}
}
此处为连接
<?php
$host = "localhost";
$username = "root";
$password = "";
$db = "db_uas_pwd_2017";
mysql_connect($host, $username, $password) or die (mysql_error());
mysql_select_db($db);
$mysqli = mysql_connect($host, $username, $password, $db);
答案 0 :(得分:0)
您的SQL代码错误。您需要在SQL代码中指定列名称。例如,SQL应该看起来像这样
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
并且,mysql_已被折旧,现在PHP建议使用mysqli_或PDO。有关更多参考资料,请访问以下链接:
来自xXAlphaManXx的答案,15岁