Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\xampp\htdocs\a_upload\upload.php on line 71
Warning: mysql_query() [function.mysql-query]: Error reading result set's header in C:\xampp\htdocs\a_upload\upload.php on line 71
GalleryUploadMessageProfileStatistticsChange PasswordDelete Account
if(!$sql=mysql_query("INSERT INTO image VALUES(NULL, '$user_id_db', '$image', '$image_keyword_p' ,
'$image_full_name', '$image_short_name_p', '$image_des_p','$file_size' ,'$image_resolution', 0)"))
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\a_upload\upload.php on line 130
LINE 130: $image = mysql_fetch_assoc($image); //get access to image table
----------------------------------------------------------------------------------------------------------------
upload.php
<?php
include("include/header.php");
$file = isset($_FILES['fileupload']) ? $_FILES['fileupload']['tmp_name'] : false;
$upload_error = "";
//check, if user is loged in or not
if(isset($_SESSION['username'])) /*** user is loged in ***/
{
//user get submit button
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(empty($_POST['image_short_name']) || empty($_POST['image_des']))
{
$upload_error .= "Missing field! Please fill in all field!";
}
else
{
$user = $_SESSION['username']; //get name of who is loged in
$id = $_SESSION['user_id'];
$image_short_name_p = $_POST['image_short_name'];
$image_keyword_p = $_POST['image_keyword'];
$image_des_p = $_POST['image_des'];
//check for existing names
$query = mysql_query("Select * FROM image WHERE image_short_name = '$image_short_name_p' AND user_id='$id'");
if(mysql_num_rows($query) >= 1)
{
$upload_error .= "That image name is already taken";
}
else
{
if($file)
{
//scussess - store image in $image
$image = chunk_split(base64_encode(file_get_contents($_FILES['fileupload']['tmp_name'])));
//store image name in $image_full_name(.jpeg)
$image_full_name = $_FILES['fileupload']['name'];
//store image size in $image_size, change it to 100x100
$image_width_height = getimagesize($_FILES['fileupload']['tmp_name']);
$image_resolution = $image_width_height[0] . "X" . $image_width_height[1];
//get size of image in binary, change $file_size to b, kb, mb, or gd
$file_size = filesize($file);
if ($file_size < 1024) { $file_size = $file_size . " B"; }
else if($file_size < 1048576) { $file_size = round($file_size / 1024, 2) . " KB"; }
else if($file_size < 1073741824) { $file_size = round($file_size / 1048576, 2) . ' MB'; }
else if ($file_size < 1099511627776) { $file_size = round($file_size / 1073741824, 2) . ' GB'; }
//test to see if it is an image
if($image_width_height == FALSE)
{
$upload_error .= "Thats not a image";
}
else
{
//Image is too big, change it to KB's
if(strstr($file_size, 'M') || strstr($file_size, 'G'))
{
$upload_error .= "image is too big";
}
//get user id and sote in user_id_db(user thats loged in select his rows)
$queryget = mysql_query("SELECT user_id FROM user WHERE username = '$user'");
$row = mysql_fetch_assoc($queryget);
$user_id_db = $row['user_id'];
//insert information into database
if(!$sql=mysql_query("INSERT INTO image VALUES(NULL, '$user_id_db', '$image', '$image_keyword_p' ,
'$image_full_name', '$image_short_name_p', '$image_des_p','$file_size' ,'$image_resolution', 0)"))
{
$upload_error .= "problem uploading image. please try again";
}
else
{
}
}
}
else
{
$upload_error .= "Select an image!";
}
}
}
}
}
else
{
header('Location: error.php');
}
$_SESSION['upload_error'] = $upload_error;
?>
hwoarang69
11
Newbie Poster
Recommended Answers
Jump to PostMySQL server has gone away
Means you somehow lost connection to the server.
Jump to PostPerhaps it loses the connection because the upload takes too long. Try connecting to the database, AFTER the file is done.
Jump to PostFirewall, router... can be anything really. Most likely is a short wait timeout on the server. You can try to connect, query and close right after each other and see if that works.
Jump to PostDoes the code work if you omit the upload part ? If not, delete more until it works. Then start putting stuff back in again.
All 13 Replies
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
hwoarang69
11
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
hwoarang69
11
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
hwoarang69
11
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
hwoarang69
11
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
hwoarang69
11
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
hwoarang69
11
Newbie Poster
pritaeas
2,194
¯\_(ツ)_/¯
Moderator
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.