Recoverable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\CRUD 4\UPLOAD\upload\upcode.php on line 46
I write code but when excute code I'm find Error : Recoverable fatal error Object of class mysqli could not be converted to string
$insertquery="insert into tbl_user(username,image)values('{$username}','{$file_name}')";
$iquery=mysqli_query($con,$insertquery) or die($con);
print_r($iquery);
exit;
<?php
include '../dbconnect.php';
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['submit']) and !empty($_POST['submit'])){
$username=isset($_POST['username'])?$_POST['username']:NULL;
if(is_null($username) or empty($username)){
header("location:{$_REQUEST['/']}?action=username&msg=blank-username");
exit;
}
$file=$_FILES['file'];
$file_name = $file['name'];
$file_type = $file['type'];
$file_tmp_name = $file['tmp_name'];
$file_error = $file['error'];
$file_size = $file['size'];
$fs = $file_size/1024;
$arr = ['jpg','png','jpeg'];
$fi= explode(".",$file_name);
$last = end($fi);
if(in_array($last,$arr))
{
if($fs<=500)
{
if($file_error==0)
{
$file_path = __DIR__."/vv/";
$upload_files = $file_path.$file_name;
if( move_uploaded_file($file_tmp_name,$upload_files))
{
$insertquery="insert into tbl_user(username,image)values('{$username}','{$file_name}')";
$iquery=mysqli_query($con,$insertquery) or die($con);
//print_r($iquery);
//exit;
if($iquery){
?>
<script>
window.alert("File Uploaded successfully");
</script>
<?php
}else{
?>
<script>
window.alert("Uploading failed");
// window.location.href="register.php";
</script>
<?php
}
}else{
echo "No File Movienig";
}
}else{
echo "File Uploading Error";
}
}else{
echo "File Size Should be bellow 500kb";
}
}else{
echo "<br> InValid image";
}
}else{
header("location:{$_REQUEST['/']}");
}
}else{
header("location:register.php");
}
Solutions :
First Check Your Databse Connection
Connection Error : If you try this : mysqli_select_db($con,'image_db');
<?php
$con =mysqli_connect('localhost:3308','root','');
mysqli_select_db($con,'image_db');
?>
<?php
$con =mysqli_connect('localhost:3308','root','','imgae_db');
if($con){
echo "No Coonection";
}else{
echo "Coonection Succesfully";
}
?>
or
<?php
$con =mysqli_connect('localhost:3308','root','','imgae_db');
?>
0 Comments