简体   繁体   中英

Cant store the image to the database using php

I am trying to upload an image in my database from HTML form. I have written the PHP code and I have an error message

     <form action="login.php" method="post" enctype="multipart/form-data">
         user<input type="text" name="user_name1"  required />
           password<input type="password" name="password1" required />
             Email<input type="email" name="email11" required />     
Upload any image you want<input type="file" name="image">
  <input  class="submit" type="submit" name="submit2" value="sign up"/>

            </form>

and this is the PHP code

  <?php

     if(array_key_exists('submit2',$_POST))
{

$user=$_POST['user_name1'];
$pass=$_POST['password1'];
$email=$_POST['email11'];
$image=addcslashes($_FILES['image']['tmp_name']);
$image_name=addcslashes($_FILES['image']['name']);
$image2=file_get_contents($image);
$image3=base64_encode($image2);
$query9="insert into login  values('$user','$pass','$email','$image3','$image_name')";
if(mysqli_query($conn,$query9))

echo "Insert is successful";

else

echo "Error ".$query9."<br>".mysqli_error($conn);



}

mysqli_close($conn);
?>      

This is the error I get after executing the code

Warning: addcslashes() expects exactly 2 parameters, 1 given in

You are using addcslashes which requires 2 parameters, the first being the string, and the second, a list of characters you want to escape.

I believe you want to use addslashes which will return your string with backslashes before characters that need to be escaped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM