Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html><head></head>
- <body>
- <form method="post" action="" enctype="multipart/form-data">
- Upload File:
- <input type="file" name="upload" /><br>
- <input type="submit" name="submit" value="Submit"/>
- </form>
- </body>
- </html>
- <?php
- $servername ="localhost";
- $username = "root";
- $password = "";
- $dbname = "produ_db";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- if(isset($_POST['submit']) ){
- if ($_FILES['upload']['name'] == 0 ){
- $filename = $conn->real_escape_string($_FILES['upload']['name']);
- $filedata= $conn->real_escape_string(file_get_contents($_FILES['upload']['tmp_name']));
- echo "Error: unable to store image";
- }
- else {
- /*where acc_cap is the image caption && acc_img is a blob type to store images*/
- $query = "INSERT INTO accessories(`acc_cap`,`acc_img`) VALUES ('$filename','$filedata')" ;
- if ($conn->query($query) === TRUE) {
- echo "<br><br> New record created successfully";
- } else {
- echo "Error:<br>" . $conn->error;
- }
- }
- $conn->close();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement