มันerrorแบบนี้ เวลาคลิกส่งข้อมูลค่ะ แล้วข้อมูลก็ไม่databaseค่ะ
Parameter must be an array or an object that implements Countable in /home/kembanga/public_html/user/save_subcon.php on line 31
นี้full code ค่ะ
<?php
require_once "config.php";
//check if form is submitted
if (isset($_POST['submit']))
{
$name = $_POST['fname'];
$notel = $_POST['notel'];
$nmasyarikat = $_POST['nmasya'];
$nopendsya = $_POST['pendsya'];
$lokasi1=implode(' ',$_POST['lokasi']);
$skop1=implode(' ',$_POST['sk']);
$nota = $_POST['nota'];
$kmhr1=implode(' , ',$_POST['kmhr']);
$filename = $_FILES['filename']['name'];
//upload file
if($filename != '')
{
//allowed file type
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = ['pdf', 'txt', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif', 'excel', 'mp4', 'xls','png'];
//check if file type is valid
if (in_array($ext, $allowed))
{
// get last record id
$sql = 'select max(id) as id from information';
$query_sql = mysqli_query($link, $sql);
if (count($query_sql) > 0) //errorตรงนี้
{
$row = mysqli_fetch_array($query_sql);
$filename = ($row['id']+1) . '-' . $filename;
}
else{
$filename = '1' . '-' . $filename;
}
//set target directory
$path = 'uploads/';
if (!is_dir($path)) {
echo 'error';
} else {
//Save the uploaded file from the database in the created folder.
move_uploaded_file($_FILES['filename']['tmp_name'],($path . $filename));
}
// insert file details into database
$sql = "INSERT INTO information(id,name,notel,nmasyarikat,nopendsya,lokasi,skop,pekerja,kemahiran,document)
VALUES (NULL,'".$name."','".$notel."','".$nmasyarikat."','".$nopendsya."','".$lokasi1."','".$skop1."','".$nota."','".$kmhr1."','".$filename."')";
$query_sql=mysqli_query($link,$sql);
//noti after submit and go to main page
echo "<script>
window.location.href='subcon.php';
alert('Maklumat anda telah disimpan. Terima Kasih');
</script>";
}
else
{
//Display when the file type does not match the specified file type.
echo mysqli_connect_error($link);
echo'<script>alert("Maklumat ini tidak boleh disimpan(Jenis fail ini tidak dibenarkan.)")</script>';
}
}
else
//Shown when the file has not been uploaded.
echo "<script>
window.location.href='subcon.php';
alert('Mestikan file document diupload. Terima Kasih');
</script>";
}
?>
พอมีใครช่วนได้มั้ยคะ
error แบบนี้แก้ยังไงได้บ้างคะ Parameter must be an array or an object that implements Countable
Parameter must be an array or an object that implements Countable in /home/kembanga/public_html/user/save_subcon.php on line 31
นี้full code ค่ะ
<?php
require_once "config.php";
//check if form is submitted
if (isset($_POST['submit']))
{
$name = $_POST['fname'];
$notel = $_POST['notel'];
$nmasyarikat = $_POST['nmasya'];
$nopendsya = $_POST['pendsya'];
$lokasi1=implode(' ',$_POST['lokasi']);
$skop1=implode(' ',$_POST['sk']);
$nota = $_POST['nota'];
$kmhr1=implode(' , ',$_POST['kmhr']);
$filename = $_FILES['filename']['name'];
//upload file
if($filename != '')
{
//allowed file type
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$allowed = ['pdf', 'txt', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif', 'excel', 'mp4', 'xls','png'];
//check if file type is valid
if (in_array($ext, $allowed))
{
// get last record id
$sql = 'select max(id) as id from information';
$query_sql = mysqli_query($link, $sql);
if (count($query_sql) > 0) //errorตรงนี้
{
$row = mysqli_fetch_array($query_sql);
$filename = ($row['id']+1) . '-' . $filename;
}
else{
$filename = '1' . '-' . $filename;
}
//set target directory
$path = 'uploads/';
if (!is_dir($path)) {
echo 'error';
} else {
//Save the uploaded file from the database in the created folder.
move_uploaded_file($_FILES['filename']['tmp_name'],($path . $filename));
}
// insert file details into database
$sql = "INSERT INTO information(id,name,notel,nmasyarikat,nopendsya,lokasi,skop,pekerja,kemahiran,document)
VALUES (NULL,'".$name."','".$notel."','".$nmasyarikat."','".$nopendsya."','".$lokasi1."','".$skop1."','".$nota."','".$kmhr1."','".$filename."')";
$query_sql=mysqli_query($link,$sql);
//noti after submit and go to main page
echo "<script>
window.location.href='subcon.php';
alert('Maklumat anda telah disimpan. Terima Kasih');
</script>";
}
else
{
//Display when the file type does not match the specified file type.
echo mysqli_connect_error($link);
echo'<script>alert("Maklumat ini tidak boleh disimpan(Jenis fail ini tidak dibenarkan.)")</script>';
}
}
else
//Shown when the file has not been uploaded.
echo "<script>
window.location.href='subcon.php';
alert('Mestikan file document diupload. Terima Kasih');
</script>";
}
?>
พอมีใครช่วนได้มั้ยคะ