0

I am getting the following errors while uploading an image on phpmysql through wamp server.

1. MySQL server has gone away in C:\wamp\www\storeinfo.php on line 15

2. Error reading result set's header in C:\wamp\www\storeinfo.php on line 15

The code is given below:

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","");
$db = mysql_select_db("imagestore",$conn);
if(!$db)
{
    echo mysql_error();
}
$rollNo = $_POST['rollNo'];
$image = addslashes (file_get_contents($_FILES['image']['tmp_name']));
$image_s=getimagesize($_FILES['image']['tmp_name']);
$imgtype = $image_s['mime'];
$q = "INSERT INTO students VALUES('','$rollNo','$image','$imgtype')";
$r=mysql_query($q, $conn);
if($r)
{
    echo "Information stored successfully";
}
else
{
    echo mysql_error();
}

?>

How to remove these errors?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Tasneem
  • 118
  • 2
  • 14

2 Answers2

0

Please check the data type of the image field in the database. It must be longblob not blob. May be that is the reason it is not able to accept large files.

Nimitt Shah
  • 4,477
  • 2
  • 10
  • 21
0

Q 1.MySQL server has gone away in C:\wamp\www\storeinfo.php on line 15

This means you mysql server is not working properly, first you need to check if you mylsq server is working fine (try to use mysqlWorkBench or something like that)

Q 2: Error reading result set's header in C:\wamp\www\storeinfo.php on line 15

This means your file is printing something before the headers are sending, usually this happens when you try to print some image and you have some echo before

Also I would suggest to use mysqli or PDO instead of mysql_connect, since it is already deprecated https://phpdelusions.net/pdo