Fatal error: Call to a member function query() on resource in C:\AppServ\www\product\config.php on line 22
โค๊ด
<?php
// Include the database configuration file
include_once 'Connections/dbconn.php';
$statusMsg = '';
// File upload directory
$targetDir = "img/";
if(isset($_POST["submit"])){
if(!empty($_FILES["file"]["name"])){
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
// Allow certain file formats
$allowTypes = array('jpg','png','jpeg','gif');
if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
// Insert image file name into database
$insert = $dbconn->query("INSERT INTO images (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
if($insert){
$statusMsg = "The file ".$fileName. " has been uploaded successfully.";
}else{
$statusMsg = "File upload failed, please try again.";
}
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}else{
$statusMsg = 'Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.';
}
}else{
$statusMsg = 'Please select a file to upload.';
}
}
// Display status message
echo $statusMsg;
?>
โค๊ดเชื่อมต่อ database
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_dbconn = "localhost";
$database_dbconn = "shopping";
$username_dbconn = "root";
$password_dbconn = "12345678";
$dbconn = mysql_pconnect($hostname_dbconn, $username_dbconn, $password_dbconn) or trigger_error(mysql_error(),E_USER_ERROR);
?>
ผมเขียนผิดตรงไหนหรอคับ
ผมจะinsertภาพลง data base แต่มันขึ้นแบบนี้คับ
โค๊ด
<?php
// Include the database configuration file
include_once 'Connections/dbconn.php';
$statusMsg = '';
// File upload directory
$targetDir = "img/";
if(isset($_POST["submit"])){
if(!empty($_FILES["file"]["name"])){
$fileName = basename($_FILES["file"]["name"]);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
// Allow certain file formats
$allowTypes = array('jpg','png','jpeg','gif');
if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
// Insert image file name into database
$insert = $dbconn->query("INSERT INTO images (file_name, uploaded_on) VALUES ('".$fileName."', NOW())");
if($insert){
$statusMsg = "The file ".$fileName. " has been uploaded successfully.";
}else{
$statusMsg = "File upload failed, please try again.";
}
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}else{
$statusMsg = 'Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.';
}
}else{
$statusMsg = 'Please select a file to upload.';
}
}
// Display status message
echo $statusMsg;
?>
โค๊ดเชื่อมต่อ database
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_dbconn = "localhost";
$database_dbconn = "shopping";
$username_dbconn = "root";
$password_dbconn = "12345678";
$dbconn = mysql_pconnect($hostname_dbconn, $username_dbconn, $password_dbconn) or trigger_error(mysql_error(),E_USER_ERROR);
?>
ผมเขียนผิดตรงไหนหรอคับ