Help needed. Errors in php codes
Posted: Wed Nov 16, 2011 8:41 pm
Im new in php and now Im developing a simple webpage to insert information. I keep on getting the error "Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\projectli\mainadd1.php on line 29" and "Warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\projectli\mainadd1.php on line 31 ". This happens when i tried to insert a data in the database. The data is inserted without problems but I'm trying to do some error handling since I don't want any duplicate data in my database. I hope I can get help here since Ive already searching for solutions elsewhere with no success.
Below are the code for the page.
If it helps this are the code for connect.php and the database
Below are the code for the page.
Code: Select all
<?php
if(isset($_POST['submitted'])) {
include('connect.php');
$id=$_POST['id'];
$negeri=$_POST['negeri'];
$daerah=$_POST['daerah'];
$pkg=$_POST['pkg'];
$kod_sekolah=$_POST['kod_sekolah'];
$nama_sekolah=$_POST['nama_sekolah'];
$ptj=$_POST['ptj'];
$server=$_POST['server'];
$pc=$_POST['pc'];
$nb=$_POST['nb'];
$mono_laser=$_POST['mono_laser'];
$color_laser=$_POST['color_laser'];
$dot_matrix=$_POST['dot_matrix'];
$lcd=$_POST['lcd'];
$set_lan=$_POST['set_lan'];
$jumlah_kos=$_POST['jumlah_kos'];
$dibayar=$_POST['dibayar'];
$tanggungan=$_POST['tanggungan'];
if($negeri){
if($daerah){
if($pkg){
if($kod_sekolah){
$q1=mysqli_query("SELECT * FROM schools where kod_sekolah = '".$_POST['kod_sekolah']."'");
$q2=mysqli_fetch_object($dbcon,$q1);
if($q2->kod_sekolah == $_POST['kod_sekolah']){
die('<br><br>There is already "'.$q2->kod_sekolah.'" in the database, please choose another Kod Sekolah.');
}
if($nama_sekolah){
$sqlinsert="INSERT INTO schools (id, negeri, daerah, pkg, kod_sekolah, nama_sekolah, ptj, server, pc, nb, mono_laser,
color_laser, dot_matrix, lcd, set_lan, jumlah_kos, dibayar, tanggungan)
VALUES ('$id','$negeri', '$daerah', '$pkg', '$kod_sekolah', '$nama_sekolah', '$ptj', '$server', '$pc', '$nb',
'$mono_laser',
'$color_laser','$dot_matrix', '$lcd', '$set_lan', '$jumlah_kos', '$dibayar', '$tanggungan')";
if(!mysqli_query($dbcon, $sqlinsert)){
die('error inserting new record');
}
$errormsg = "1 Record Has Been Inserted";
}
else
$errormsg="Please Complete Nama Sekolah Field";
}
else
$errormsg="Please Complete Kod Sekolah Field";
}
else
$errormsg="Please Complete PKG Field";
}
else
$errormsg="Please Complete Daerah Field";
}
else
$errormsg="Please Complete Negeri Field";
}
?>
If it helps this are the code for connect.php and the database
Code: Select all
<?php
$dbcon=mysqli_connect("localhost","root","", "project");
?>