phpMyAdmin records into table are not seen

A

Anonymous

Guest
Hello everyone,

I am new to this forum and also into php:)

I have a problem sending data from a html form to MariaDB using PHP. I have connection established and right now I am just able to see records ( id ) and not values I entered.

My html code is simple :
Code:
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

And after this I am using the php to send data to MariaDB, the records are not visible unfortunately :
Code:
<?php
$servername = "localhost";
$username = "root";
$password = "************";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO Form (name, email)
VALUES ('$_POST[post_name]', '$_POST[post_email]')";

if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

You can see in the attachments the problem(test.png && db.png). I enter records and the I can not see them in phpmyadmin on the db.
I am using CentOS 7, PHP version: 7.2.34, nginx/1.21.3, and phpmyadmin 4.4.15.10, 5.5.68-MariaDB Server and database structure is the following ( attachments db.png)


Thank you in advance and sorry if someone posted already this topic.
Alex
 

Attachments

  • php.PNG
    php.PNG
    41.4 KB · Views: 1,154
  • test.PNG
    test.PNG
    4.1 KB · Views: 1,154
  • db.PNG
    db.PNG
    94.9 KB · Views: 1,154
I haven't used mysqli in a long time, so I won't be able to help you out. However, I would recommend using PDO as it would be easier. Here's a good link that I still use from time to time - https://phpdelusions.net/pdo

From the looks of the screenshots that is the structure of the database table and not the data. You created the table, but it isn't working when you try to add values to it. The id has to be auto incremented and a primary key.
 
Your code references $_POST[post_name] and $_POST[post_email]'), but these names aren't on your form; you've called the inputs "name" and "email". Change your parameter names to $_POST['name'] and $_POST['email'] and it should work.

As an aside, PHP can tell you about things like this if you let it. Look into enabling error reporting on your environment.
 
Back
Top