Mara_2 -4 Newbie Poster

I need to create a database from the messages, coming from the Mobirise website builder's forms. What code should I use?
This doesn't work. Could you please help me.

$link = mysqli_connect('localhost', 'root', 'password'); 
if (!$link) 
{ 
  $output = 'Unable to connect to the database server.'; 
  include 'output.html.php'; 
  exit(); 
}

Dani AI

Generated

— short, practical plan for saving Mobirise form submissions into MySQL.

Mobirise form blocks can either use the built-in Formoid processor or be pointed at a custom server script by setting the form action; pointing the form to a PHP endpoint is the usual way to collect submissions on your own server. (mobirise.com)

Create a database and a simple table to hold messages (example schema):

CREATE DATABASE IF NOT EXISTS mobirise_forms CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE mobirise_forms;

CREATE TABLE messages (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(255),
  subject VARCHAR(255),
  message TEXT NOT NULL,
  ip VARCHAR(45),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

See the MySQL reference for CREATE TABLE details. (dev.mysql.com)

Accept POST data and insert it safely using PDO with prepared statements (simplified example):

<?php
$dsn = 'mysql:host=127.0.0.1;dbname=mobirise_forms;charset=utf8mb4';
$u = 'formuser'; $p = 'secret';
$pdo = new PDO($dsn, $u, $p, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES=>false]);

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $name = trim($_POST['name'] ?? '');
  $email = trim($_POST['email'] ?? '');
  $msg  = trim($_POST['message'] ?? '');

  if (!filter_var($email, FILTER_VALIDATE_EMAIL) || $msg === '') { http_response_code(400); exit; }

  $stmt = $pdo->prepare('INSERT INTO messages (name,email,message,ip) VALUES (:n,:e,:m,:ip)');
  $stmt->execute([':n'=>$name,':e'=>$email,':m'=>$msg,':ip'=>$_SERVER['REMOTE_ADDR'] ?? '']);
  http_response_code(201); echo 'OK';
}

Use PDO and prepared statements to avoid SQL injection and use PHP's filters for basic validation. (php.net)

Troubleshooting notes: the original snippet opens a server connection but doesn’t show a selected database or insert step — ensure the DB name is provided and credentials are correct. Check server/PHP error logs, confirm the PDO (or mysqli) extension is installed, and test the form action by submitting directly (curl/Postman). If using mysqli, remember mysqli_connect returns false on failure and mysqli_connect_error() gives the reason. (php.net)

Security/ops reminders: keep DB credentials out of webroot (use environment vars), don’t enable error display in production, and rate-limit or CAPTCHA forms to prevent spam.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.