Upload, Insert, Update, Delete an Image using PHP MySQL | Coding Cage

Upload, Insert, Update, Delete an Image using PHP MySQL

By
Hello friends, after a long time i am going to post a simple tutorial yet useful in your web application or project, Simple Insert, Select, Update and Delete (CRUD) with Image using PDO Query. an Image will be Uploaded, Inserted, Updated and Deleted as well with MySQL. we already have a CRUD Tutorials but i haven't covered this, this tutorial is covered with proper image validation, let say only valid image extensions are allowed to upload and image size is also matters. So let'see image upload in php.
Upload, Insert, Update, Delete an Image using PHP MySQL
 

Database / Table

"testdb" named database is used in this tutorial, so create it and paste the following sql code in your phpmyadmin it will create users table "tbl_users".

CREATE TABLE IF NOT EXISTS `tbl_users` (
  `userID` int(11) NOT NULL AUTO_INCREMENT,
  `userName` varchar(20) NOT NULL,
  `userProfession` varchar(50) NOT NULL,
  `userPic` varchar(200) NOT NULL,
  PRIMARY KEY (`userID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ;

now we have to create only 4 files php files which will handle our crud operations with an image and they are as follow.

dbconfig.php

simple host/database configuration file created with PDO Query/Extension. change the credentials as per your configuration.
<?php

 $DB_HOST = 'localhost';
 $DB_USER = 'root';
 $DB_PASS = '';
 $DB_NAME = 'testdb';
 
 try{
  $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USER,$DB_PASS);
  $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
 catch(PDOException $e){
  echo $e->getMessage();
 }

addnew.php

Simple HTML form created with bootstrap, the fields i have taken here for user is username, userjob, and userimage, you can also add more fields.
<form method="post" enctype="multipart/form-data" class="form-horizontal">
     
 <table class="table table-bordered table-responsive">
 
    <tr>
     <td><label class="control-label">Username.</label></td>
        <td><input class="form-control" type="text" name="user_name" placeholder="Enter Username" value="<?php echo $username; ?>" /></td>
    </tr>
    
    <tr>
     <td><label class="control-label">Profession(Job).</label></td>
        <td><input class="form-control" type="text" name="user_job" placeholder="Your Profession" value="<?php echo $userjob; ?>" /></td>
    </tr>
    
    <tr>
     <td><label class="control-label">Profile Img.</label></td>
        <td><input class="input-group" type="file" name="user_image" accept="image/*" /></td>
    </tr>
    
    <tr>
        <td colspan="2"><button type="submit" name="btnsave" class="btn btn-default">
        <span class="glyphicon glyphicon-save"></span> &nbsp; save
        </button>
        </td>
    </tr>
    
    </table>
    
</form>

The above form will look like :


Upload, Insert, Update, Delete an Image using PHP MySQL - Insert Form

as i told that, i have used her bootstrap for this tutorial so actual file code looks lengthy, that's why i have putted here only important and main code, the designing code is avoided. now let come to the next point.




PHP Code :

put the following php code just above starting <!DOCTYPE html> tag. in this script an image and user details will be inserted, proper image validation is there or if any error occured an appropriate message will be displayed with bootstrap design.
<?php
 error_reporting( ~E_NOTICE ); // avoid notice
 require_once 'dbconfig.php';
 
 if(isset($_POST['btnsave']))
 {
  $username = $_POST['user_name'];// user name
  $userjob = $_POST['user_job'];// user email
  
  $imgFile = $_FILES['user_image']['name'];
  $tmp_dir = $_FILES['user_image']['tmp_name'];
  $imgSize = $_FILES['user_image']['size'];
  
  
  if(empty($username)){
   $errMSG = "Please Enter Username.";
  }
  else if(empty($userjob)){
   $errMSG = "Please Enter Your Job Work.";
  }
  else if(empty($imgFile)){
   $errMSG = "Please Select Image File.";
  }
  else
  {
   $upload_dir = 'user_images/'; // upload directory
 
   $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
  
   // valid image extensions
   $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
  
   // rename uploading image
   $userpic = rand(1000,1000000).".".$imgExt;
    
   // allow valid image file formats
   if(in_array($imgExt, $valid_extensions)){   
    // Check file size '5MB'
    if($imgSize < 5000000)    {
     move_uploaded_file($tmp_dir,$upload_dir.$userpic);
    }
    else{
     $errMSG = "Sorry, your file is too large.";
    }
   }
   else{
    $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";  
   }
  }
  
  
  // if no error occured, continue ....
  if(!isset($errMSG))
  {
   $stmt = $DB_con->prepare('INSERT INTO tbl_users(userName,userProfession,userPic) VALUES(:uname, :ujob, :upic)');
   $stmt->bindParam(':uname',$username);
   $stmt->bindParam(':ujob',$userjob);
   $stmt->bindParam(':upic',$userpic);
   
   if($stmt->execute())
   {
    $successMSG = "new record succesfully inserted ...";
    header("refresh:5;index.php"); // redirects image view page after 5 seconds.
   }
   else
   {
    $errMSG = "error while inserting....";
   }
  }
 }
?>

editform.php

editing form is simple like an insert form is, the complete code is given in the downloadable file. while editing a record we have to fetch selected record from database, if image is selected to edit then old image will be deleted and new image will be uploaded, here is the only PHP script.
<?php
 error_reporting( ~E_NOTICE );
 require_once 'dbconfig.php';
 
 if(isset($_GET['edit_id']) && !empty($_GET['edit_id']))
 {
  $id = $_GET['edit_id'];
  $stmt_edit = $DB_con->prepare('SELECT userName, userProfession, userPic FROM tbl_users WHERE userID =:uid');
  $stmt_edit->execute(array(':uid'=>$id));
  $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
  extract($edit_row);
 }
 else
 {
  header("Location: index.php");
 }
 
 if(isset($_POST['btn_save_updates']))
 {
  $username = $_POST['user_name'];// user name
  $userjob = $_POST['user_job'];// user email
   
  $imgFile = $_FILES['user_image']['name'];
  $tmp_dir = $_FILES['user_image']['tmp_name'];
  $imgSize = $_FILES['user_image']['size'];
     
  if($imgFile)
  {
   $upload_dir = 'user_images/'; // upload directory 
   $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
   $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
   $userpic = rand(1000,1000000).".".$imgExt;
   if(in_array($imgExt, $valid_extensions))
   {   
    if($imgSize < 5000000)
    {
     unlink($upload_dir.$edit_row['userPic']);
     move_uploaded_file($tmp_dir,$upload_dir.$userpic);
    }
    else
    {
     $errMSG = "Sorry, your file is too large it should be less then 5MB";
    }
   }
   else
   {
    $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";  
   } 
  }
  else
  {
   // if no image selected the old image remain as it is.
   $userpic = $edit_row['userPic']; // old image from database
  } 
      
  
  // if no error occured, continue ....
  if(!isset($errMSG))
  {
   $stmt = $DB_con->prepare('UPDATE tbl_users 
              SET userName=:uname, 
               userProfession=:ujob, 
               userPic=:upic 
               WHERE userID=:uid');
   $stmt->bindParam(':uname',$username);
   $stmt->bindParam(':ujob',$userjob);
   $stmt->bindParam(':upic',$userpic);
   $stmt->bindParam(':uid',$id);
    
   if($stmt->execute()){
    ?>
                <script>
    alert('Successfully Updated ...');
    window.location.href='index.php';
    </script>
                <?php
   }
   else{
    $errMSG = "Sorry Data Could Not Updated !";
   }
  }    
 }
?>

Updating form will look like :


Upload, Insert, Update, Delete an Image using PHP MySQL - Update Form

now the next step is record displaying along with image, well using bootstrap it easy to create an image gallery let's have a look at the script.

index.php

within div tag class="row" an image gallery thumbnail will be generated from users table.
<div class="row">
<?php
 
 $stmt = $DB_con->prepare('SELECT userID, userName, userProfession, userPic FROM tbl_users ORDER BY userID DESC');
 $stmt->execute();
 
 if($stmt->rowCount() > 0)
 {
  while($row=$stmt->fetch(PDO::FETCH_ASSOC))
  {
   extract($row);
   ?>
   <div class="col-xs-3">
    <p class="page-header"><?php echo $userName."&nbsp;/&nbsp;".$userProfession; ?></p>
    <img src="user_images/<?php echo $row['userPic']; ?>" class="img-rounded" width="250px" height="250px" />
    <p class="page-header">
    <span>
    <a class="btn btn-info" href="editform.php?edit_id=<?php echo $row['userID']; ?>" title="click for edit" onclick="return confirm('sure to edit ?')"><span class="glyphicon glyphicon-edit"></span> Edit</a> 
    <a class="btn btn-danger" href="?delete_id=<?php echo $row['userID']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
    </span>
    </p>
   </div>       
   <?php
  }
 }
 else
 {
  ?>
        <div class="col-xs-12">
         <div class="alert alert-warning">
             <span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ...
            </div>
        </div>
        <?php
 }
 
?>
</div>

Gallery will look like :


Creating Image Gallery using PHP MySQL

Deleting Record with Image

Now Put the following code just above <html> tag within "index.php" or you can create new page to delete record like "delete.php" just hyperlink the page name along with record id
if(isset($_GET['delete_id']))
 {
  // select image from db to delete
  $stmt_select = $DB_con->prepare('SELECT userPic FROM tbl_users WHERE userID =:uid');
  $stmt_select->execute(array(':uid'=>$_GET['delete_id']));
  $imgRow=$stmt_select->fetch(PDO::FETCH_ASSOC);
  unlink("user_images/".$imgRow['userPic']);
  
  // it will delete an actual record from db
  $stmt_delete = $DB_con->prepare('DELETE FROM tbl_users WHERE userID =:uid');
  $stmt_delete->bindParam(':uid',$_GET['delete_id']);
  $stmt_delete->execute();
  
  header("Location: index.php");
 }



that's it, here you can download this complete code and try in your localhost server, this was just for beginners (beginner level) hence we can also create file uploading class to avoid reuse of file uploading and we can also use Object Oriented way to achieve the same, hope you like it. please do share.



124 comments:

  1. Replies
    1. Hi Denis, Glad you liked it :)

      Delete
    2. Possible with images multiple upload ?

      Delete
    3. Hi Denis,
      if i got time i will post this tutorial :)

      Delete
    4. Hi Pradeep, I tried the tutorial and im getting an error Warning: move_uploaded_file(user_images/978781.png): failed to open stream: No such file or directory in C:\xampp\htdocs\snapcatch\addnew.php on line 40

      Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpEC85.tmp' to 'user_images/978781.png' in C:\xampp\htdocs\snapcatch\addnew.php on line 40

      Can you help please? thank you -Brian

      Delete
  2. Mr.Khodke this is an excellent job. Thank you

    ReplyDelete
    Replies
    1. You're welcome, Bishwajit :)
      thanks for the valuable comment ...

      Delete
    2. How to use thiss script code in your 'oophp Mysql pagination Script using php pdo'?

      Delete
    3. How to use this script to insert update and delete image code in your 'PHP PDO CRUD Tutorial using OOP with Bootstrap' published previously?

      Delete
    4. Hi Bishwajit,
      try to make it yourself with oop,pagination we have PHP PDO CRUD tutorial so prefer it and try, if you got some difficulties then you can contact me for the query, cause i don't have time right now, i already have some college and other pending projects so i couldn't give time for it. hope you understand :)

      Delete
  3. Elegant and very useful, thank you.

    ReplyDelete
    Replies
    1. Thanks Gabriel, Glad you liked it...

      Delete
  4. where i need tyo put the dbconfig.php

    ReplyDelete
    Replies
    1. hello remmel,

      you can put this file in your root folder or you can also put it within sub folder like class/dbconfig.php but be sure to change the including path in required files.

      Delete
  5. I done something wrong, on the top of the page:

    prepare('SELECT userPic FROM tbl_users WHERE userID =:uid'); $stmt_select->execute(array(':uid'=>$_GET['delete_id'])); $imgRow=$stmt_select->fetch(PDO::FETCH_ASSOC); unlink("user_images/".$imgRow['userPic']); // it will delete an actual record from db $stmt_delete = $DB_con->prepare('DELETE FROM tbl_users WHERE userID =:uid'); $stmt_delete->bindParam(':uid',$_GET['delete_id']); $stmt_delete->execute(); header("Location: index.php"); } ?>

    All html/css is good, im front-end maker so i know something about this, but i know nothing about mysql. Where data should be loaded/prepare execute there is line of code. I tried to create database and table again and again and still doesnt work. Can you help me?

    ReplyDelete
    Replies
    1. Hello Mierzwinski,
      it's a simple script to understand, i have used her PDO Query/Extension to make this script, prepare() statement makes query and bindParam bind the value for the sql query and finally execute() function executes the query.

      the first part is to delete image from the folder
      the second part is to delete the same row from the mysql table

      Delete
  6. Hi Pradeep. Thank you for the effort to post these tutorials for our newbies.
    My database gets updated, but the images does not move into the image directory.
    I am using ubuntu LAMP. Any ideas?

    ReplyDelete
    Replies
    1. Hello there,
      make sure you have properly created image directory.

      Delete
  7. Thank you dedicating time to teach our newbies on these concepts.
    I have copied the code as is, and although the database gets updated perfectly, the images does not go into the directory - ie. MOVE_UPLOADED does not workon my Ubuntu LAMP installation - no errors are given.

    ReplyDelete
  8. this is Great STUFF KEEP the good work up!

    ReplyDelete
  9. Didn"t work mysql is wrong

    ReplyDelete
  10. Great script!

    How would you address orientation problems when uploading photos from mobile?

    Here is a code example:



    ReplyDelete
  11. Great script!

    How would you address orientation issues when uploading photos from mobile?

    ReplyDelete
  12. Do you have any example if you want an Article with two imagens for example (multiple upload).

    ReplyDelete
  13. hi how can i insert into database and echo message sent using this PDO

    ReplyDelete
  14. WOW!
    Great example.
    I do have a question. I am new to PHP. How do I resize the image to be stored to 300 wide by 200 high?
    Thank you in advance,
    Terry Schroeder

    ReplyDelete
  15. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about php

    ReplyDelete
  16. Hi Pradeep Khodke

    Thank you very much for this great tutorial. I found this script very useful.I'm new in Object Oriented php and struggling to learn. I tried to modify your script to object oriented function with multiple upload feature but i ended nowhere.

    Please could you help on how to:
    1.  Redesign the script for multiple image upload,
    2.  User being able to delete appropriate image before upload,
    3.  Showing progress bar on multiple image upload process,
    4. After submission of image and related info the script will display information with the first added image with url to detail.php page for showing the rest featured images and related info,
    5. Restrict the image upload of a size below 300 pixels height and width,
    6. Control each image with size of 200 pixels height to 200 pixels width on display,
    7. Restrict more than six image uploads,
    8. Enable the success or error message to display on the same submission form using post-get-redirect method.

    *Script must be designed in Object Oriented php functions, CRUD operation performed on calling functions.

    Looking you forward for a kind help.
    Germa.

    ReplyDelete
  17. After testing these codes several times i found there is a problem with addnew.php file.The file only uploads one image and fails to upload another image until the first image is deleted. What could be the problem?

    ReplyDelete
  18. when I copy paste ur first 2 codes.."dbconfig.php nd addnew.php" nd i launch it in my navigator ..It comes to me Undefined variable: userprofession nd username

    ReplyDelete
    Replies
    1. Please i don't want to repeat the same question here but i also have the same problem.
      Please any help?

      Delete
  19. when I copy paste ur first 2 codes"dbconfig.php nd addnew.php" It comes to me Undefined variable: userprofession nd user name..What could be d problem?

    ReplyDelete
  20. I've been trying to integrate this into an already build registration and login system but i'm having tro

    ReplyDelete
  21. Fatal error: Call to a member function prepare() on boolean in C:\xampp\htdocs\Digits_Parents\edit-profile.php on line 58



    please help me

    ReplyDelete
  22. Hello i have a problem, i get an error in my code - "Sorry, only JPG, JPEG, PNG and GIF files are allowed." any suggestions what should i do?

    ReplyDelete
    Replies
    1. hello there, it's a image validation, only valid image extensions are allowed to upload, you can remove it .. to upload what you want , just remove the validation code :)

      Delete
  23. sir you are very great teacher i like you

    ReplyDelete
  24. facing a problem in index.php
    ( ! ) Notice: Undefined variable: DB_con in C:\wamp\www\new\index.php on line 5

    how can i do plaese tell

    ReplyDelete
  25. hola como cargo mas de una foto?

    ReplyDelete
  26. hello, as I upload more than one photo, the esoy trying and I get errors. also want q if no load a default image from another folder . you help me?

    ReplyDelete
  27. could not find driver
    Fatal error: Call to a member function prepare() on a non-object in C:\AppServ\www\img\addnew.php on line 57 - $stmt = $DB_con->prepare('INSERT INTO tbl_users(userName,userProfession,userPic) VALUES(:uname, :ujob, :upic)');

    how to fix it? thanks

    ReplyDelete
    Replies
    1. hello there, it seems pdo driver is not enabled in your localhost, enable it

      make following changes in php.ini file

      ;extension=php_pdo.dll
      ;extension=php_pdo_mysql.dll

      to

      extension=php_pdo.dll
      extension=php_pdo_mysql.dll

      and restart your server, that's it

      Delete
  28. Hi,
    thank you for coding, but I cant no more download code! :-(

    BottyE

    ReplyDelete
  29. how to add thumbnail this is code

    ReplyDelete
  30. Wow, Awesome Tutorial thanks for share (y)

    ReplyDelete
  31. You saved my life man! Thanks!

    ReplyDelete
  32. Great PRADEEP, thank you for your tips,
    your code is running in Brazil.

    ReplyDelete
    Replies
    1. I am glad, Fernando, keep visiting...

      Delete
    2. Hellow Mr Pradeep I've done everything instructed to do the, view all page does'nt show the image I uploaded after saving I'm using a server online .com ,is there anything else that I need to add for the coding to work.?

      Delete
    3. May you please help me please.i realyy love what you have done here and would like to use it for my project.Please

      Delete
  33. hi i'm getting following error on index.php
    Parse error: syntax error, unexpected end of file in .\index.php on line 120
    fresh installation any idea how to fix

    ReplyDelete
  34. Mr.Pradeep Khodke very nice work you've done,but I'm having a little problem.I just uploaded all the files currently added new user and saved the details and waited nothing is happening .So I wana know is it just the files you gave us we have to work with or is there anything else extra we have to accomplish before the coding works.?

    ReplyDelete
    Replies
    1. Hi there, sorry for the late reply, and yes, you just have to download the code and configure the database file with your local/server database credentials, that's it,
      if it's still not working then do let me know via comment ...

      Delete
    2. appear Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'' in C:\xampp\htdocs\Upload\addnew.php:62 Stack trace: #0 C:\xampp\htdocs\Upload\addnew.php(62): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\Upload\addnew.php on line 62

      please solution thanks????

      Delete
  35. Thank you very much for the tutorial :)

    ReplyDelete
    Replies
    1. Hello, editform.php is not working..how to fixed?

      Delete
  36. nice tutorial... how can i add search in your code..can u help me for this

    ReplyDelete
  37. nice tutorial..can i ask how can i add search box in your code?

    ReplyDelete
  38. editform.php not working bro? T_T

    ReplyDelete
  39. how to insert data in MySQLi Procedural format

    ReplyDelete
  40. Very Nice work,I would like to know can I extend Database with the exact coding you compiled here.
    I need to have more database being captured.

    ReplyDelete
  41. Please Pradeep can u help me extend the database.

    ReplyDelete
  42. i want to upload multiple images in this script.
    what i do..?????
    plzz help me

    ReplyDelete
  43. Thanks for the code.. The image is deleted only from the database record . I want the image to be deleted from both the database record and user_images Folder. How can i do that?? Thanks in advance.

    ReplyDelete
  44. i have code to update profile data...but if user not update their pic than it doesn't show old pic...how to solve it???

    ReplyDelete
  45. hello,thank you very much for this tuturial ,it was very useful for me.
    can you guide me for creating a pin for deleting and editing?
    can you guide me for creating this delete and edit system with personal ability every body control his delete and edit not other person?
    thank you so much sincerly yours,arash

    ReplyDelete
  46. sir please help. this is work properly but i add a new i encounter this error

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in C:\xampp\htdocs\sad2016\testonly2newdesign\insertformimage\addnew.php:77 Stack trace: #0 C:\xampp\htdocs\sad2016\testonly2newdesign\insertformimage\addnew.php(77): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\sad2016\testonly2newdesign\insertformimage\addnew.php on line 77

    ReplyDelete

  47. emerging Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'' in C:\xampp\htdocs\Upload\addnew.php:62 Stack trace: #0 C:\xampp\htdocs\Upload\addnew.php(62): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\Upload\addnew.php on line 62
    solution please thanks????

    ReplyDelete
  48. Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'' in C:\xampp\htdocs\Upload\addnew.php:62 Stack trace: #0 C:\xampp\htdocs\Upload\addnew.php(62): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\Upload\addnew.php on line 62

    emerging solution please thanks....?

    ReplyDelete
  49. Hello Pradeep. Thank you for the work you're doing. I used this tutorial, everything works well, but for the update part. I get this error report "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='34'' at line 23' in C:\wamp\www\www.libertynigeria.com\edit_member.php:164 Stack trace: #0 C:\wamp\www\www.libertynigeria.com\edit_member.php(164): PDOStatement->execute() #1 {main} thrown in C:\wamp\www\www.libertynigeria.com\edit_member.php on line 164". PLEASE HELP. WHAT SHOULD I DO?

    ReplyDelete
  50. Good tutorial thank you PRADEEP can you please provide me rating with email in php

    ReplyDelete
  51. can i ask ?
    i get error , this error message :

    Fatal error: Uncaught Error: Call to a member function bindParam() on boolean in C:\xampp\htdocs\Project PI+DB\processdb.php:46 Stack trace: #0 {main} thrown in ......

    ReplyDelete
  52. Thank for this cool code, My index page is not displaying images, it display "No Data Found ... " how do I fix this

    ReplyDelete
  53. How to add crop features here?

    ReplyDelete
  54. Thank you very much for the tutorial, but could you teach how to add/update multiple image?

    ReplyDelete
  55. Thank you very much for the tutorial, but could you teach how to add or update for multiple image?

    ReplyDelete
  56. Looking forward to reading more. Great article.Really looking forward to read more. Keep writing.
    Sap Fiori

    ReplyDelete
  57. Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]

    ReplyDelete
  58. i got this from edit....can you help me??
    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]

    ReplyDelete
  59. hi sir why i cannot edit this .. if i click edit it appear only index .. ?

    ReplyDelete
  60. can you make one for mysqli, i got errors in the coding

    ReplyDelete
  61. Thank you very much for the tutorial .... This is very helpful..
    I want to add search features such as the datatable but it was very difficult .. ^_^

    ReplyDelete
  62. i have a problem in my application, i can update all the content in 1 form, but why i cant update the picture?

    ReplyDelete
  63. At last i have found such kind of website. Thanks every post

    ReplyDelete
    Replies
    1. Hello MD Masud,
      thanks for the kind words, and keep visiting :)

      Delete
  64. hello there i copy and paste your code but i have an error can you please help me to solve this following error Notice: Undefined variable: DB_con in C:\xampp\htdocs\projectv2\index.php on line 4

    Fatal error: Call to a member function prepare() on null in C:\xampp\htdocs\projectv2\index.php on line 4

    thank you so much

    ReplyDelete
    Replies
    1. Hi Alsan, Did you make some changes in this code ? if so please let me know ..., i may try to help you.

      Delete
  65. Help Please!

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL)' at line 1' in C:\xampp\htdocs\progressus\Progressus\profilepic\addnew.php:76 Stack trace: #0 C:\xampp\htdocs\progressus\Progressus\profilepic\addnew.php(76): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\progressus\Progressus\profilepic\addnew.php on line 76

    ReplyDelete
  66. how about with mysqli? i'm not familiar with PDO. .

    ReplyDelete
  67. Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\xampp\htdocs\upload\addnew.php:57 Stack trace: #0 {main} thrown in C:\xampp\htdocs\upload\addnew.php on line 57

    ReplyDelete
  68. Everything are ok but images are not visible.. (there is nor any error message)

    ReplyDelete
  69. nice tutorial,
    i find new here, about "extract" , i have never use before :D

    ReplyDelete
  70. Hi Pradeep, nice tutorial. I've been trying to follow in your footsteps but I've been received an error - Fatal error: Cannot use object of type PDOStatement as array in C:\wamp64\www\res-app\modules\admin\admin-processes.php on line 142

    On line 142, I'm keeping the old image in a variable just like you've explained -

    else {
    $edit_up_image = $records['admin_image'];
    }

    Could you please tell me what might be causing this error? TIA.

    ReplyDelete
  71. Everything are ok but images are not visible..
    But give erro:-

    Notice: Undefined variable: edit_row in C:\xampp\htdocs\check\index1.php on line 113

    Warning: unlink(upload/): Permission denied in C:\xampp\htdocs\check\index1.php on line 113

    ReplyDelete
  72. can u please update with pagination and search box it will help me

    ReplyDelete
  73. Notice: Undefined index: user_image in C:\wamp\www\shopping\admin\pages\product_edit.php on line 233

    Notice: Undefined index: user_image in C:\wamp\www\shopping\admin\pages\product_edit.php on line 234

    Notice: Undefined index: user_image in C:\wamp\www\shopping\admin\pages\product_edit.php on line 235


    plz help me...

    ReplyDelete
  74. Notice: Undefined index: user_image in C:\wamp\www\shopping\admin\pages\product_edit.php on line 233

    Notice: Undefined index: user_image in C:\wamp\www\shopping\admin\pages\product_edit.php on line 234

    Notice: Undefined index: user_image in C:\wamp\www\shopping\admin\pages\product_edit.php on line 235

    ReplyDelete
  75. Wonderful Tutorials.

    Waiting to see password reset and user profile update tutorial

    Thanks

    ReplyDelete
  76. Hi ,
    I have a problem while uploading image.images greater than 5 mb also gets uploaded. No error message is shown.

    if($imgSize < 5000000) {
    move_uploaded_file($tmp_dir,$upload_dir.$userpic);
    }


    if condition is not working? What can be the possible reason. please help me

    ReplyDelete
  77. the image file isn't uploaded to folder, why?

    ReplyDelete
  78. the image file isn't uploaded to folder, why?

    ReplyDelete
  79. how i can download this file

    ReplyDelete
  80. Hi Thanks for the very useful code. I want the upload.php part to only show specific name or profession how do I do that?

    ReplyDelete
  81. prepare('SELECT userID, userName, userProfession, userPic FROM tbl_users ORDER BY userID DESC');
    $stmt->execute();

    I have set the userProffesion to have 4 different values Teacher, Nurse, doctor, lawyer. I want to display only teachers in the Gallery how do I do that

    ReplyDelete
  82. Hello, great job!!!

    Everithing is ok, but i´m having a problem.

    This is the problem:

    Warning: unlink(../../../d.sesnando/3242jnfjsfs.PNG)[funtion.unlink]: No such file or directory in /home/pg27925/public_html/d.sesnando/vinho/img_update/editform.php on line 47

    this is my line 47:

    unlink($upload_dir.$edit_row['imagem']);

    Thanks for your time and the great job :)


    ReplyDelete
  83. Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ..Best PHP Training in Chennai|PHP Training in Chennai

    ReplyDelete