Trouble subimitting data with a form

Hi everybody

I’m trying to make a form to submit data to my PHPMyAdmin database.
The php to connect seems to work fine but when I try to submit data from the form it gives me the error “error inserting new record”. Is there anybody out there who can tell me what I’m doing wrong?

Here’s the html for the form:

Insert Data into the Customers table

Add your company
to the database




Postal Code


Street and Nr

General Telephone number

General Email


Domain of Email


And here is the php:<?php
$sql=“INSERT INTO Customers (CustId, Company, Country, PostalCode, City, StreetAndNr, GenTel, GenMail, Website, Domain) VALUES (’$CustId’, ‘$Company’, ‘$Country’, ‘$PostalCode’, ‘$City’, ‘$StreetAndNr’, ‘$GenTel’, ‘$GenMail’, ‘$Website’, ‘$Domain’)”;

if (!mysqli_query($dbcon, $sql)) {
die (‘error inserting new record’);
$answer = “1 record added to the database”;

This is the connect file in php:

DEFINE (‘DB_USER’, ‘Any userr’);
DEFINE (‘DB_PSWD’, ‘Any password’);
DEFINE (‘DB_HOST’, ‘localhost’);

$dbcon = mysqli_connect (DB_HOST, DB_USER, DB_PSWD, DB_NAME);
if (!$dbcon){
die (‘error connecting to database’);
//echo ‘you have connected succesfully’;
The names of user, password and db have been replaced by dummy values.

Much appreciated.


A) Whatever forum you pasted that code from onto this forum, isn’t compatible with the forum formatting used here. Paste your original code in this forum and use the forum’s preformatted text </> menu button.
B) Please read the recent ‘form’ submit topics on this forum to find out what your code should be doing so that it is secure, provides a good user experience, and will either work or it will display/log the reason why it doesn’t work.

Several problems with your code. The most obvious the raw data from the form is being handled. You should look into the “filter_input()” function to protect from users hacking your database. Or, upgrade to PDO which is now the preferred use of databases.
Here is a link that shows one example that might help you. This site is a learning site and has examples of all languages, forms, code, etc that might help you get started. Also, please make sure you use the tags so we can copy your code easier.
filter_input Example
Simple Form Example (Use POST version)
Hope this helps you get started…

Sponsor our Newsletter | Privacy Policy | Terms of Service