Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- echo '<div id="content" class="container" style="new.css">';
- echo '<form action="Addproducts.php" method="post" enctype="multipart/form-data" class="form-horizontal well col-xs-8 col-xs-offset-2">';
- echo '<input type="text" id="text" name="image_text"></input>';
- echo ' <div class="form-group">';
- echo '<input type="file" name="image"/>';
- echo '</div>';
- echo ' <div class="form-group">';
- echo ' <center> <input type="submit" name="submit" value="Enter"/> </center>';
- echo ' </div>';
- echo '</form>';
- //end of html part
- if(isset($_POST["submit"]))
- {
- $dbHost = 'localhost';
- $dbUsername = 'root';
- $dbPassword = '';
- $dbName = 'mydb';
- $image = $_FILES['image']['name'];
- $mysqli = new mysqli("localhost", "root", "", "mydb");
- $image_text = mysqli_real_escape_string($mysqli , $_POST['image_text']);
- move_uploaded_file($_FILES['image']['tmp_name'],"images/".$_FILES['image']['name']);
- $path ="images/".$_FILES['image']['name'] ;
- $imgContent = basename($_FILES['image']['tmp_name']) ;
- $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
- if($db->connect_error)
- {
- die("Connection failed: " . $db->connect_error);
- }
- $insert = $db->query("INSERT into products(product_Image,product_name,Image_path) VALUES ('$imgContent','$image_text','$path' )");
- $target = "images/".basename($image);
- move_uploaded_file($image, $target) ;
- if($insert)
- {
- echo "<center>Image inserted successfully</center>";
- }
- else
- echo "<center> Error in inserting image </center>";
- }
- echo ' </div>';
- ?>
- <?php
- echo '<div class="panel panel-primary">';
- echo '<div class="panel-body">';
- echo '<form action="" method="post" enctype="multipart/form-data" class="form-horizontal well col-xs-8 col-xs-offset-2">';
- echo '<input type="text" name="image_text" class="form-control"></input>';
- echo ' <div class="form-group">';
- echo '<input type="file" class="form-control" name="image"/>';
- echo ' </div>';
- echo ' <input type="submit" name="submit" value="Enter" /> ';
- echo '</form>';
Add Comment
Please, Sign In to add comment