File manager - Edit - /home/custbahd/public_html/dbmanager/add.php
Back
<?php //including the database connection file include_once("config.php"); $msg = ""; if(isset($_POST['Submit'])) { $name = mysqli_real_escape_string($mysqli, $_POST['name']); $code = mysqli_real_escape_string($mysqli, $_POST['code']); $price = mysqli_real_escape_string($mysqli, $_POST['price']); $description = mysqli_real_escape_string($mysqli, $_POST['description']); $image = mysqli_real_escape_string($mysqli, $_FILES['image']['name']); $target = "images/".basename($_FILES['image']['name']); // checking empty fields if(empty($name) || empty($code) || empty($price) || empty($image)) { if(empty($name)) { echo "<font color='red'>Name field is empty.</font><br/>"; } if(empty($code)) { echo "<font color='red'>Code field is empty.</font><br/>"; } if(empty($price)) { echo "<font color='red'>Price field is empty.</font><br/>"; } if(empty($description)) { echo "<font color='red'>Description field is empty.</font><br/>"; } if(empty($image)) { echo "<font color='red'>Image not selected.</font><br/>"; } //link to the previous page echo "<br/><a href='javascript:self.history.back();'>Go Back</a>"; } else { // if all the fields are filled (not empty) //insert data to database $result = mysqli_query($mysqli, "INSERT INTO hotdogs(name,code,price,description,image) VALUES('$name','$code','$price','$description','$image')"); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "There was a problem uploading image"; } //display success message echo "<font color='green'>Data added successfully."; echo "<br/><a href='index.php'>View Result</a>"; } } ?> <html> <head> <title>Add Product</title> </head> <body> <a href="index.php">Home</a> <br/><br/> <form action="add.php" method="post" name="form1" enctype="multipart/form-data"> <table width="25%" border="0"> <tr> <td>Name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Code</td> <td><input type="text" name="code"></td> </tr> <tr> <td>Price</td> <td><input type="text" name="price"></td> </tr> <tr> <td>Description</td> <td><textarea type="text" name="description"></textarea></td> </tr> <tr> <td>Image</td> <td><input type="file" name="image"></td> </tr> <tr> <td></td> <td><input type="submit" name="Submit" value="Add"></td> </tr> </table> </form> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Generation time: 0.48 |
proxy
|
phpinfo
|
Settings