0

I'm trying to upload three images and few texts related to car using PHP and MYSQL. Initially the i got the message " MYSQL has gone away.." so I increased the max_packet size to 500M . .The database name, table name are correct.

Following is the php code I have used.

<?php
        if(isset($_POST["submit"])) 
        {
                $check1 = getimagesize($_FILES["image1"]["tmp_name"]);
                $check2 = getimagesize($_FILES["image2"]["tmp_name"]);
                $check3 = getimagesize($_FILES["image3"]["tmp_name"]);

                if($check1 !== false and $check2 !== false and $check3 !== false)    
                {        

                    $img1 = $_FILES['image1']['tmp_name'];
                    $imgContent1 = addslashes(file_get_contents($img1));
                    $frontimg = $imgContent1;

                    $img2 = $_FILES['image2']['tmp_name'];
                    $imgContent2 = addslashes(file_get_contents($img2));
                    $backimg = $imgContent2;

                    $img3 = $_FILES['image3']['tmp_name'];
                    $imgContent3 = addslashes(file_get_contents($img3));
                    $intimg = $imgContent3;

                    $kms      = htmlentities($_POST["kms"]);
                    $make     = htmlentities($_POST["make"]);
                    $model = htmlentities($_POST["model"]);
                    $variant = htmlentities($_POST["variant"]);
                    $reg = htmlentities($_POST["year"]);
                    $color = htmlentities($_POST["color"]);
                    $owner = htmlentities($_POST["owner"]);
                    $price = htmlentities($_POST["price"]);

                    $dbHost     = 'localhost';
                    $dbUsername = 'root';
                    $dbPassword = '';
                    $dbName     = 'car';


                    $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

                    // Check connection
                    if($db->connect_error)
                    {
                        die("Connection failed: " . $db->connect_error);
                    }
                    $insert = $db->query("  insert into car( frontimg, backimg, intimg, kms, make, model, variant, reg, color, owner, price ) 
                                                       values ('$frontimg', '$backimg', '$intimg','$kms','$make', '$model', '$variant', '$reg', '$color', 
                                                       '$owner','$price')  ");   

                    if($insert)
                    {

                             echo "data stored successfully";

                    }
                    else
                    {
                        echo "Check your query";
                    }   

                } 
            }
?>

The php is returning the text " Check your query " indicating the error in the SQL code. What might have gone wrong here..

Rohit S
  • 395
  • 4
  • 18
  • 2
    try to echo out the query and run it on the phpMyAdmin – Wils Mar 27 '18 at 08:18
  • 1
    Try letting PHP show errors, then you'll have more info to debug. https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings – Dhruv Murarka Mar 27 '18 at 08:22
  • @Wils If i try to echo the images , I get screen full of junk characters.. – Rohit S Mar 27 '18 at 08:27
  • error_reporting(E_ALL); ini_set('display_errors', 1); put these at the top of page & run the page , what it shows? – Mohit Kumar Mar 27 '18 at 08:36
  • @MohitKumar .. Again i just got " Check your query"..which is written in the else part..! – Rohit S Mar 27 '18 at 08:39
  • echo & die ur insert query & run it in phpmyadmin, what it shows output? – Mohit Kumar Mar 27 '18 at 08:45
  • I tried to upload the images of size 5KB..it WORKED.. But getting error while uploading large files... – Rohit S Mar 27 '18 at 08:50
  • @RohitS why you are storing images on database? Store uploaded image in directory and in data base only store its name – B. Desai Mar 27 '18 at 09:03
  • You're probably exceeding your maximum query size, which for a typical mysql install is only 1MB. – Nick Mar 27 '18 at 11:06
  • @Nick... Is there a way to increase the max query size..?? – Rohit S Mar 27 '18 at 12:46
  • Sure (if you have the appropriate privilege), you can `SET GLOBAL max_allowed_packet = x` where x is any integer value up to 1GB (1073741824). But on re-reading I see you already did that... sorry don't know how I missed that the first time. – Nick Mar 27 '18 at 21:22

0 Answers0