Hi,
I am learning PHP. But I am trying to save into my mysql Database.
When I click on the save button its saving without bugg's message but my DB still blank. I do verify all the connection's functions (there is not problem). But my DB doesnt receive any datas. Can I have a solution please?
index.php
- include('server.php'); ?>
Add to create, update, delete Database records - "stylesheet" type="text/css" href="style.css">
- if(isset($_SESSION['msg'])): ?>
- class= "msg">
- echo $_SESSION['msg'];
- unset($_SESSION['msg']);
- ?>
- endif ?>
Name Address "2">Action - while ($row = mysqli_fetch_array($results)) ?>
echo $row['name']; ?> echo $row['address']; ?> - "#">Edit
- "#">Delete
- action="server.php">
- class="input-group">
- "text" name="name">
- class="input-group">
- "type" name="address">
- class="input-group">
- name="save" class="btn">Save
server.php
- // initialize variables
- $name = "";
- $address = "";
- $id = 0;
- // connect to database
- $db = mysqli_connect('localhost:3307','root','','crud1');
- // if save button is clicked
- if (isset($_POST['save'])) {
- $name = $_POST['name'];
- $address = $_POST['address'];
- $query = "INSERT INTO info (name, address) VALUES ('$name', '$address')";
- mysqli_query($db, $query);
- $_SESSION['msg'] = "Address saved";
- header('location: index.php'); // redirect to index page after inserting
- }
- // retrieve records
- $results = mysqli_query($db, "SELECT * FROM info");
- ?>
style.css
- body {
- font-size: 19px;
- }
- table{
- width: 50px;
- margin: 30px auto;
- border-collapse: collapse;
- text-align: left;
- }
- tr{
- border-bottom: 1px solid #cbcbcb;
- }
- th, td{
- border: none;
- height: 30px;
- padding: 2px;
- }
- tr:hover{
- background: #f5f5f5;
- }
- form{
- width: 45%;
- margin: 50px auto;
- text-align: left;
- padding: 20px;
- border: 1px solid #bbbbbb;
- border-radius: 5px;
- }
- .input-group{
- margin: 10px 0px 10px 0px;
- }
- .input-group label{
- display: block;
- text-align: left;
- margin: 3px;
- }
- .input-group input{
- height: 30px;
- width: 93%;
- padding: 5px 10px;
- font-size: 16px;
- border-radius: 5px;
- border: 1px solid gray;
- }
- .btn {
- padding: 10px;
- font-size: 15px;
- color: white;
- background: #5F9EA0;
- border: none;
- border-radius: 5px;
- }.msg{
- margin: 30px auto;
- padding: 10px;
- border-radius: 5px;
- color: #3c763d;
- background: #dff0d8;
- width: 50%;
- text-align: center;
- }
IsraelPosted Aug 29, 2020, 7:24 AM
IsraelPosted Aug 28, 2020, 7:42 AM
Navaneeth KrishnanPosted Aug 27, 2020, 8:29 PM
IsraelPosted Aug 27, 2020, 2:26 PM