I’m having issues with linking the database (phpmyadmin) to my files in visual code (PHP files)
I’m a new web programmer so most likely I forgot something pretty obvious.
This is my registration.html
class
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Registration</title>
<meta http-equiv="refresh" content="43200">
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<div class="bg_img" id="site_content">
<h3 id="msg" style="display:none; color:rgb(246, 211, 255);">
New record created successfully
</h3>
<body id="top">
<div id="header">
<div id="logo">
<img src="img/logo.png" width="130"/>
<a href="#" class="hbutton">sign in</a>
<a href="#" class="hbutton">sign up</a>
</div>
<div id="menubar">
<ul id="menu">
<li ><a href="Home.html">Home</a></li>
<li class="selected"><a href="about.html">about us</a></li>
<li><a href="contactus.html">Contact us</a></li>
<li><a href="productlist.html">Product List</a></li>
<li><a href="registration.html">Product Registration</a></li>
<li><a href="profile.html">Profile</a></li>
<li class="dropdown">
<a href="product.html" class="drop-btn">Product Gallery</a>
<div class="dropdown-content">
<a href="OralCare.html">Oral Care</a>
<a href="SkinCare.html">Skin care</a>
<a href="PresonalCare.html">Personal Care</a>
<a href="NailCare.html">Nails care</a>
<a href="Haircare.html">Hair Care</a>
</div>
</li>
</ul>
</div>
<script>
function save(a){
alert(a);
}
var window,location,herf;
if (url.includes('msg'))document.getElementById("msg").style.desplay='block';
</script>
</div>
<div class="contrainer">
<header>Product Registration</header>
<form method = "post" action="register.php">
<div class = "productreg">
<span class="title"> </span>
<div class="fields">
<div class="input-fields">
<label>Product Name: </label>
<input type = "text" placeholder="enter the name of the product" required name="name">
</div>
<div class="input-fields">
<label>price: </label>
<input type = "text" placeholder="enter the price of the product" required name="price">
</div>
<div class="input-fields">
<label>Product description</label>
<input type = "text" placeholder="enter small description of the product" required name="description">
</div>
</div>
<div class="input-fields">
<label>code number</label>
<input type = "text" pattern="[0-9]{2}-[0-9]{3}" placeholder="Enter product code (e.g., 11-123)" required name="code">
</div>
<div class="input-fields">
<label>country of origin</label>
<input type = "text" placeholder="enter the country of origin of the product" required name="country">
</div>
<div class="input-fields">
<label>expiration date</label>
<input type = "date" placeholder="enter the expiration date of the product" required name="expire">
</div>
<button type="submit">Register Product</button>
<button type="button" onclick="clearProducts()">Clear Products</button>
</div>
</div>
</form>
</body>
<br>
<footer>
<div class="footerContainer">
<div class="socialIcons">
<a href=""><i class="fa-brands fa-facebook"></i></a>
<a href=""><i class="fa-brands fa-instagram"></i></a>
<a href=""><i class="fa-brands fa-twitter"></i></a>
<a href=""><i class="fa-brands fa-google-plus"></i></a>
<a href=""><i class="fa-brands fa-youtube"></i></a>
</div>
</div>
<script>
function clearProducts() {
// Send a request to clear.php (implementation not shown here)
}
</script>
<script>
setTimeout(function() {
location.reload();
}, 12 * 60 * 60 * 1000);
</script>
<div class="footerBottom">
<p>Copyright © 2024 Soft Care</span></p>
</div>
</footer>
</html>
and this is my php file register.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "product";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name=$_POST['name'];
$price=$_POST['price'];
$Code=$_POST['Code'];
$country=$_POST['country'];
$city=$_POST['city'];
$expiration_date=$_POST['expiration_date'];
$sql = "INSERT INTO `products` ( `name`, `price`, `Code`, `country`, 'city', 'expiration_date')
VALUES ( '$name', '$price', '$Code', '$country', 'city', '$expiration_date','$Category');";
//echo $sql; exit;
if ($conn->query($sql) === TRUE) {
header("Location: product_register.html#msg");
die();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
and I have a database in phpmyadmin the table called product
I tried everything with the PHP code / is there something I should do to connect it not only the code?
I’m developing a skin care website so I wanter to make a page like this
(It’s a bit messy because I was trying to connect the DB to the Php) store the data into the database with later will appear on the List Product section
also how to make the clear button
modhi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.