javascript - My image is not uploading after click "upload" button into database -


i'm uploading image database after clicking uploading button, it's not uploaded database, it's refresh , when add pic manually database it's website, here pic

click here

here source code upload image:

    <?php include('lock.php');  mysqli_connect("localhost", "root", "bhawanku", "members");  if(isset($_post['emp_name'])){      $content=file_get_contents($_files['pic']['tmp_name']);      @list(, , $imtype, ) = getimagesize($_files['pic']['tmp_name']);      if ($imtype == 3){         $ext="png";     }elseif ($imtype == 2){         $ext="jpeg";     }elseif ($imtype == 1){         $ext="gif";     }      $q="insert employees set empname='".$_post['emp_name']."',profile_pic='".$content."',ext='".$ext."'";     mysql_query($q);     header("location: getting_started.php"); } ?>  <html> <head>     <title>getting started..</title> </head> <style>     body{         background-color: #993333;     }      #box{         -webkit-box-shadow: 0px 0px 10px 0px rgba(110, 48, 50, 0.75);         -moz-box-shadow: 0px 0px 10px 0px rgba(110, 48, 50, 0.75);         box-shadow: 0px 0px 10px 0px rgba(110, 48, 50, 0.75);         background-color: #f0f0f0;         position: fixed;         width: 70%;         left: 18%;         top: 8%;         height: 70%;     }      #user_pic{         position: absolute;         top: 18%;         left: 12%;     }      h1{         position: fixed;         left: 19%;         font-family: throw hands in air;     }      #btn_pos{         position: absolute;         left: 45%;         top: 38%;     }      #next_btn{         border:1px solid #2a2c2f; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 7px 30px 8px 30px; text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #ffffff;         background-color: #45484d; background-image: -webkit-gradient(linear, left top, left bottom, from(#45484d), to(#000000));         background-image: -webkit-linear-gradient(top, #45484d, #000000);         background-image: -moz-linear-gradient(top, #45484d, #000000);         background-image: -ms-linear-gradient(top, #45484d, #000000);         background-image: -o-linear-gradient(top, #45484d, #000000);         background-image: linear-gradient(to bottom, #45484d, #000000);filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#45484d, endcolorstr=#000000);         margin: 140px 0px 0px 220px;         cursor: pointer;     }      #btn_upload{         border:1px solid #2a2c2f; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 7px 30px 10px 30px; text-decoration:none; display:inline-block;text-shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #ffffff;         background-color: #45484d; background-image: -webkit-gradient(linear, left top, left bottom, from(#45484d), to(#000000));         background-image: -webkit-linear-gradient(top, #45484d, #000000);         background-image: -moz-linear-gradient(top, #45484d, #000000);         background-image: -ms-linear-gradient(top, #45484d, #000000);         background-image: -o-linear-gradient(top, #45484d, #000000);         background-image: linear-gradient(to bottom, #45484d, #000000);filter:progid:dximagetransform.microsoft.gradient(gradienttype=0,startcolorstr=#45484d, endcolorstr=#000000);         margin: 10px 0px 0px 0px;         cursor: pointer;     }      #img_pos{         position: fixed;         top: 20%;         left: 22%;         width: 25%;         height: 30%;     }   </style> <body> <div id="box">     <h1>add profile pic better ;)</h1> <?php $q="select * employees"; $resultset=mysql_query($q); if(mysql_num_rows($resultset)==0){     ?>     <div id="user_pic">         <img id="img_pos" src="images/default_user.png" >     </div> <?php } while($rec=mysql_fetch_array($resultset)){     ?>         <img id="img_pos" src="load_image.php?pic_id=<?php echo $rec['id'];?>" > <?php } ?>      <div id="btn_pos">     <form method="post" action="" enctype="multipart/form-data">         <input type="file" name="pic"><br>         <button id="btn_upload" type="submit">upload now..</button>     </form>         <form>             <button id="next_btn" type="submit" name="next">next</button>         </form>     </div> </div> </body> </html> 

and here source code database:

<?php mysql_connect("localhost","root", "bhawanku"); mysql_select_db("members"); $q="select * employees id=".$_get['pic_id']; $rec=mysql_fetch_array(mysql_query($q)); $data=$rec['profile_pic']; header('content-length: '.strlen($data)); header("content-type: image/".$rec['ext']); echo $data; 

edited:-

hello, found problem causing because not using this

 <input type="text" name="emp_name" /> 

as delete code, not save pic database because of code, if use this, update pic, can tell me way has not used code , pic able upload database pls :( because problem causing due this..

you're uploading binary image data you're incorporating in text query sent database server. imagine query failing syntax error you'd never know because you're not checking errors.

as initial step change query line this:

mysql_query($q) or die(mysql_error()); 

that @ least report sql errors.

you shouldn't storing images in database - filesystem better @ - if must, use base64_encode() on file contents first.

side notes:

  • mysql_*() deprecated - use mysqli_() or pdo instead.
  • you aren't escaping $_post variables before using them in query - sql injection susceptibility. @ mysql_real_escape_string() as minimum, consider prepared statements.

edit - you're mixing mysql() , mysqli() functions. they're different , can't mixed this. use 'mysqli()' only. (thanks @phile catch).


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -