无法将数据插入数据库 [英] Can't insert the data into database
本文介绍了无法将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图插入数据并且警报仍然说我成功注册但是当我检查sql时,数据不存在。我已经尝试了很多方法,仍然无法解决它。有人可以帮帮我吗?
I tried to insert the data and the alert still say that I successfully registered but when I checked on the sql, the data is not there. I have tried numerous ways and still can't solve it. Anyone can help me?
<?php
include ('../dbcon.php');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (isset($_POST['reg_pelajar'])) {
$idmurid = mysqli_real_escape_string($db,$_POST['idmurid']);
$namamurid = mysqli_real_escape_string($db,$_POST['namamurid']);
$jantina = mysqli_real_escape_string($db,$_POST['jantina']);
$idkelas = $_POST['pkelas'];
$query = "INSERT INTO murid(`IDMurid`,`NamaMurid`,`Jantina`, `IDKelas`)VALUES ('$idmurid','$namamurid','$jantina', '$idkelas')";
if($query){
echo"<script>alert('Rekod berjaya daftar')</script>";
}else{
echo"<script>alert('Rekod gagal daftar')</script>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content="width= device-width, initial-scale= 1.0">
<title>Pendaftaran Pelajar</title>
<link rel="stylesheet" type="text/css" href="/Web/css/registerpelajar.css">
</head>
<body>
<div class "info">
<img src = "/Web/images/info.jpg" alt="addinfo" id = "add">
</div>
<div class = "Title">
Pendaftaran Pelajar
</div>
<div class = "borang">
<form action = "daftarpelajar.php" method="post">
<div class = "muridid">
No. Kad Pengenalan :
<input type = "text" name = "idmurid" placeholder = " No Kad Pengenalan " required/></br>
</div>
<div class = "muridname">
Nama Murid :
<input type = "text" name = "namamurid" placeholder = "-Nama Murid-" required/><br>
</div>
<div class = "gender">
Jantina :
<input type = "text" name = "jantina" placeholder = "-Jantina-" required/><br>
</div>
<div class = "class">
Kelas :
<select name = "pkelas" id = "pkelas">
<option value="--">Pilih Kelas</option>
<?php
$query = "SELECT * FROM kelas";
$result = mysqli_query ($db, $query);
while ($row = mysqli_fetch_array($result)):; ?>
<option value="<?=$row['IDKelas'] ?>"><?=$row['Kelas'] ?></option>
<?php endwhile; ?>
</select>
</div>
<input type ="submit" name = "reg_pelajar" value = "Register">
</form>
</div>
</body>
</html>
我的dbcon.php:
my dbcon.php:
<?php
// initializing variables
$username = "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost', 'root', '', 'harithprojek') or die("Couldn't connect"); ?>
我尝试过:
-changed选择选项
-changed变量
-add mysqli
What I have tried:
-changed the select option
-changed the variables
-add mysqli
推荐答案
_POST ['reg_pelajar'])){
_POST['reg_pelajar'])) {
idmurid = mysqli_real_escape_string(
idmurid = mysqli_real_escape_string(
db,
这篇关于无法将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文