很难在 posgresql 网站上找到用于学习目的的文档,由于某种原因,我无法通过提交表单插入数据,请帮忙,我认为我的查询是正确的,但它只是没有用
我正在使用管理员连接到我的 posgre,这是下面的代码
注册器.php
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<?php include 'connect.php';?>
<title>Index</title>
</head>
<body>
<?php
//tampung value
if(isset($_POST['submitregis'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$agama = $_POST['agama'];
$password = $_POST['password'];
$confirmpassword =$_POST['confirmpassword'];
$alamat = $_POST['alamat'];
$kota = $_POST['kota'];
$negara = $_POST['negara'];
$kodepos =$_POST['kodepos'];
//konfirmasi password
if($password != $confirmpassword){
//redirect
header('location: registrasi.php?konfirmasipassword-failed');
}else{
//insert
$insert=<<<EOF
INSERT INTO akun("nama", "email", "password", "jenis_kelamin", "agama", "alamat", "kota", "negara", "kode_pos")
VALUES ($name, $email,$gender,$agama,$password,$alamat,$kota,$negara,$kodepos);
EOF;
/*$insert=<<<EOF
INSERT INTO akun SET nama=$name, email="$email",
password="$password", jenis_kelamin="$gender",
agama="$agama",alamat="$alamat", kota="$kota",
negara="$negara", kode_pos="$kodepos";
EOF;*/
pg_query($db_handle, $insert);
header('location: registrasi.php');
}
}
/*
if(isset($_POST['submitregis'])) {
$name = $_POST['nama'];
$email = $_POST['password'];
$gender = $_POST['gender'];
$agama = $_POST['agama'];
$password = $_POST['password'];
$alamat = $_POST['alamat'];
$kota = $_POST['kota'];
$negara = $_POST['negara'];
$kodepos = $_POST['kodepos'];
$query = pg_query($db_handle, "INSERT INTO akun (nama,email,password,jenis_kelamin,
agama,alamat,kota,negara,kode_pos) VALUES ('$name','$email','$gender','$agama',
'$password','$alamat', '$kota', '$negara', '$kodepos');");
if ( $query ) {
echo "Record Successfully Updated!";
}
else{
echo "Failed";
}
}
/*function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}*/
?>
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="index.php">
<img src="logo.png" alt="Logo" style="height : 100px; width:100px;">
</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.php">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
Daftar Kursus
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="daftar_kursus.php">Cooking</a>
<a class="dropdown-item" href="#">IT dan Software</a>
<a class="dropdown-item" href="#">Design</a>
<a class="dropdown-item" href="#">Memahat</a>
<a class="dropdown-item" href="#">IT dan Software</a>
</div>
<!-- Dropdown -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
Login/Sign Up
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="Login.php">Login</a>
<a class="dropdown-item" href="registrasi.php">Sign Up</a>
</div>
</ul>
<form class="form-inline ml-auto">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<div class="card card bg-light text-dark" >
<div class="card-body">
<center> <h1>Register Yourself Here</h1> </center>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputName">Nama</label>
<span class="error">* <?php echo $nameErr;?></span>
<input type="text" name="name" class="form-control" value="<?php echo $name;?>">
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">Email</label>
<span class="error">* <?php echo $emailErr;?></span>
<input type="text" name="email" class="form-control" value="<?php echo $email;?>">
</div>
</div>
<label for="inputPassword">Password</label>
<span class="error">* <?php echo $passwordErr;?></span>
<input type="password" class="form-control" id="inputPassword" onmouseover="this.type='text'"
onmouseout="this.type='password'" placeholder="Password" name="password" value="<?php echo $email;?>">
<small id="passwordHelpBlock" class="form-text text-muted">
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
</small>
<label for="inputPassword">Confirm Password</label>
<span class="error">* <?php echo $confirmpasswordErr;?></span>
<input type="password" class="form-control" id="inputPassword" onmouseover="this.type='text'"
onmouseout="this.type='password'" placeholder="Password" name="confirmpassword" value="<?php echo $confirmpassword;?>">
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputState">Jenis Kelamin</label>
<span class="error">* <?php echo $genderErr;?></span>
<select id="inputState" class="form-control" name="gender">
<option>Perempuan</option>
<option>Laki-Laki</option>
<option>Prefer Not To Say</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="inputState">Agama</label>
<span class="error">* <?php echo $agamaErr;?></span>
<select id="inputState" class="form-control" name="agama">
<option>Islam</option>
<option>Protestan</option>
<option>Katolik</option>
<option>Hindu</option>
<option>Budha</option>
<option>Khonghucu</option>
<option>Prefer Not To Say</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputAddress">Alamat</label>
<span class="error">* <?php echo $alamatErr;?></span>
<input type="text" class="form-control" id="inputAddress" placeholder="Alamat" name="alamat">
</div>
<div class="form-row">
<div class="form-group col-md-5">
<label for="inputCity">Kota</label>
<span class="error">* <?php echo $kotaErr;?></span>
<input type="text" class="form-control" id="Kota" name="kota">
</div>
<div class="form-group col-md-4">
<label for="inputCountry">Negara</label>
<span class="error">* <?php echo $negaraErr;?></span>
<input type="text" class="form-control" id="negara" placeholder="Negara" name="negara">
</div>
<div class="form-group col-md-3" >
<label for="inputZip">Kode Pos</label>
<span class="error">* <?php echo $kodeposErr;?></span>
<input type="text" class="form-control" id="inputZip" name="kodepos">
</div>
</div>
<input type="submit" name="submitregis" value="Submit">
</form>
<?php
/*echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $password;
echo "<br>";
echo $gender;
echo "<br>";
echo $agama;
echo "<br>";
echo $alamat;
echo "<br>";
echo $kota;
echo "<br>";
echo $negara;
echo "<br>";
echo $kodepos;
echo "<br>";
*/
?>
</div>
</div>
<div class="footer">
<p>Created By GDMZ 2020</p>
</div>
</body>
</html>
我已经测试了服务器连接,一切都很好,我也可以选择数据,但我不能在我的 postgres 中插入任何数据,所以这很奇怪。