我的代码存在问题
显示
警告:mysqli_query()期望参数1为字符串,资源 在第7行的C:\ xampp \ htdocs \ ujilevel \ create-proses.php中给出
如果我将mysqli
更改为mysql
,则会显示相同的问题
之前我会展示我的config.php
$host ="localhost";
$user ="root";
$password="";
$database="portal-berita";
$koneksi=mysql_connect($host,$user,$password) or die("Koneksi error");
mysql_select_db($database,$koneksi) or die("Database tidak ditemukan");
<?php
include "config.php";
if(isset($_POST['simpan'])){
$judul=$_POST['judul'];
$isi=$_POST['isi'];
$penulis=$_POST['penulis'];
$query=mysqli_query($koneksi,"INSERT INTO berita VALUES('','$judul','$isi','','$penulis')");
if($query){
echo"<script> alert('Data Berhasil Ditambahkan !');</script>";
die("<script>location.href='home-create.php'</script>");
}
else{
echo "<script> alert('Data Gagal Ditambahkan !');</script>";
}
}
?>
第7行是$query=mysql_query($koneksi,"INSERT INTO berita VALUES('','$judul','$isi','','$penulis')");
这是我的表格
<form method="POST" action="create-proses.php">
<h2 class="card-title" >JUDUL</h2>
<input type="text" class="form-control" id="judul" name="judul" >
<br>
<h2 class="card-text">ISI</h2>
<textarea class="form-control" rows="5" name="isi"></textarea>
<br>
<h2 class="card-text">AUTHOR</h2>
<input type="text" class="form-control" id="penulis" name="penulis" >
<br>
<div class="col-sm-4">
<input type="submit" class="btn btn-primary" name="simpan" value="SUBMIT">
</form>