1

I am trying to store image and other data into MySQL using php. But other data get inserted successfully but only the image column is blank every time. I can't understand the reason behind this. This is my php code which i am using to insert data into table.

function signup($fname, $lname, $nick, $phn, $email, $pass){
    require_once 'login.php';

    $conn = new mysqli($DBhost, $DBuser, $DBpassword, $DBdatabase);
    $query = $conn->prepare('INSERT INTO USERS(FNAME,LNAME,NICK,PHN,EMAIL,PASS,PHOTO) VALUES(?,?,?,?,?,?,?)');
    $query->bind_param('sssissb', $fname, $lname, $nick, $phn, $email, $pass, file_get_contents($_FILES['photo']['tmp_name']) );
    $query->execute();
    printf("%d Row inserted.\n", $query->affected_rows);
    $query->close();
    $conn->close();
}
  • Possibly failing because the upload failed, Add this before your $conn line to see.. `$errorIndex = $_FILES["file"]["error"]; if ($errorIndex > 0) { die('We have an error #'.$errorIndex.' Try Again.'); }` – Duane Lortie Nov 02 '16 at 20:39
  • I've already tried error chacking in file uploading and it is working fine... @Duane Lortie – Premang Vikani Nov 03 '16 at 15:24
  • What's the column type of PHOTO ? Guessing it's one of the BLOB types (as it should be) Try what Ryan Vincent suggests.. Do something like `$imgblob = file_get_contents($_FILES['photo']['tmp_name'];` Then use that var for the qry – Duane Lortie Nov 03 '16 at 16:55
  • Yes, the column type of PHOTO is mediumblob. And I also tried `$imgblob = file_get_contents($_FILES['photo']['tmp_name']);` but not working @DuaneLortie – Premang Vikani Nov 03 '16 at 19:19
  • Ok, I finally managed to do this. I simply used 'sssisss' instead of 'sssissb' as the first argument of bind_param() function and it worked for me. I don't know why!!! – Premang Vikani Nov 04 '16 at 17:08

0 Answers0