php - insert into a database not working -
i having issue in inserting table. connection file correct , coming header.php. there no errors when go within table no records being inserted.
<?php include('header2.php'); if(isset($_post['done'])) { $title = $_post['title']; $description = $_post['description']; $link = $_post['link']; $company = $_post['company']; $sql = "insert placements (title, description, link, company) values ('$title', '$description', '$link','$company')"; // use exec() because no results returned echo "new record created successfully"; } ?> <html> <head> <title> add placement </title> </head> <body> <form method="post"> <input type="text" name="title" placeholder="title"> <input type="text" name="description" placeholder="description"> <input type="text" name="company" placeholder="company"> <input type="text" name="link" placeholder="link"> <input type="submit" name="done"> </form> </body> </html>
you not executing query @ all. assume database connection below , run query. should work.
tested.
$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "mydb"; // create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // check connection if (!$conn) { die("connection failed: " . mysqli_connect_error()); } if(isset($_post['done'])) { $title = $_post['title']; $description = $_post['description']; $link = $_post['link']; $company = $_post['company']; $sql = "insert placements (title, description, link, company) values ('$title', '$description', '$link','$company')"; if (mysqli_query($conn, $sql)) { echo "new record created successfully"; } else { echo "error: " . $sql . "<br>" . mysqli_error($conn); } }
Comments
Post a Comment