Exporting Form Data to a Table in phpMyAdmin

I am a beginner in this field, so I appreciate your patience with my questions.

Currently, I am working on a project that involves inputting form data into a phpMyAdmin table and sending confirmation emails to users upon successful submission.

If you'd like to see the form page, please click here.

After completing the form, a message similar to this should appear.

Unfortunately, I am encountering issues with both sending email confirmations and transferring data to the phpMyAdmin table. It seems like there are problems with the code execution, and I have reached a roadblock. Any assistance would be highly appreciated.

Below is an excerpt of the code I am working with:

<?php 
error_reporting(E_ALL ^ E_NOTICE); // suppressing basic PHP notices

$link = mysqli_connect("localhost","warren","*******","warren"); 

if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$contactname = mysqli_real_escape_string($link, $_POST['contactname']);    
$age =  mysqli_real_escape_string($link, $_POST['age']);  
$gender =  mysqli_real_escape_string($link, $_POST['sex']);
$weight =  mysqli_real_escape_string($link, $_POST['weight']);
$height =  mysqli_real_escape_string($link, $_POST['height']);
$membership =  mysqli_real_escape_string($link, $_POST['membership']);
$email =  mysqli_real_escape_string($link, $_POST['email']);

// Form submission
if(isset($_POST['Submit'])) {

    if(mysqli_real_escape_string($link, $_POST['contactName']) === '') {
        $nameError =  'Please enter your name.'; 
        $hasError = true;
    } else {
        $contactname = mysqli_real_escape_string($link, $_POST['contactName']);
    }

    if(mysqli_real_escape_string($link, $_POST['email']) === '')  {
        $nameError = 'Please provide your e-mail address.';
        $hasError = true;
    } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", mysqli_real_escape_string($link, $_POST['email']))) {
        $emailError = 'Invalid email address!';
        $hasError = true;
    } else {
        $email = mysqli_real_escape_string($link, $_POST['email']);
    }
...
... (continued section of code)</exquestionbody>
<answerscount>1</answerscount>
<answer1>
<div class="answer" i="36986831" l="3.0" m="1462205335">
<p>Assuming your <code>customer_id column has an auto increment value.

$sql = "INSERT INTO customer(contactname, age, gender, weight, height, memebership, email) 
VALUES ('$contactname', '$age', '$gender' ,  '$weight', '$height', '$membership', '$email')";

No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign NULL or 0 to the column to generate sequence numbers.

Answer №1

If your database's customer_id column is set to auto increment, you can use the following SQL code:

$sql = "INSERT INTO customer(contactname, age, gender, weight, height, membership, email) 
VALUES ('$contactname', '$age', '$gender' ,  '$weight', '$height', '$membership', '$email')";

When inserting data into a table with an AUTO_INCREMENT column, MySQL will automatically assign sequence numbers if no value is specified for the column. Alternatively, you can explicitly assign NULL or 0 to generate sequence numbers.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Javascript functions function properly only if they contain the 'alert()' command

My aim is to utilize Ajax (Javascript + php) for checking user name availability when a user moves focus to another form field. The strange part is that my functions only work when I include some alert(), without them, the functions fail to operate. Anoth ...

How can I calculate the total number of days between the from_date and to_date using PHP in CodeIgniter?

$from_date = $this->input->post('from_date');12/3/2016 $to_date = $this->input->post('to_date');14/3/2016 I am looking for a solution that will provide me with the total number of days between two dates. For example, consid ...

submit information using AJAX with jQuery

My goal is to save data in a database when a button is clicked. However, I'm facing an issue where the code works in some browsers but not in Firefox. When I click the button, an empty alert pops up and the data is not saved in the table. $("#Sav ...

Attempting to retrieve information from a PHP array

When outputting this array as JSON: $events['data'] The result is: [ { "id":"3" } ] However, attempting to access the id directly throws an error Undefined index: id, using the following code: $events['data'][' ...

What is the process for assigning a name and value to a DOMNode in PHP?

The `DOMNode` class includes the attributes `nodeName` and `nodeValue`, but lacks setters for them. It's possible to directly access the public attribute `nodeValue`, but how can one set the read-only `nodeName`? ...

Is it possible to verify credentials across multiple sources such as a database, Active Directory, and

While I have been using my own authentication and authorization code with Symfony2 as a framework, I recently decided to explore Symfony's security system. Following the tutorial on their website, I successfully set up login using my database. Howeve ...

The AJAX-MYSQL request returned a "undefined" error with a 200 OK response code

I am currently working on developing an AJAX application that allows users to input a user's ID and have all corresponding information automatically populate the remaining text fields. For example, if the user types in the ID number "1234", the fields ...

Discount on Shipping and Free Coupons at Magento

My shipping free rule is set up as follows: Applicable to all customer groups No coupon required Limited to 0 uses per customer Conditions: Cart total must be >= 100, and Shipping country must be NL, BE, or DE Free shipment available for matching items. ...

Is there a way to verify the custom form when the braintree PayPal checkout button is clicked?

I am seeking a solution to validate a custom PHP form when the Braintree PayPal checkout button is clicked. Currently, the form redirects to the PayPal screen if it is not properly filled out. My goal is to prevent the PayPal popup window from opening if ...

When the user clicks on the page, show the data fetched from MySQL and echoed in

I am facing an issue with a table containing a loan_id. When fetching the information, everything appears to be in order. However, I need to be able to click on the loan_id number and have it display results based on the corresponding id number. <?php ...

Passing data with middleware redirection

Working on my project using Laravel 5 and feeling a bit puzzled at the moment. I'm trying to check if a user is logged in using my middleware. If not, I want to generate a unique link for that particular user like so: $code = str_random(32); return r ...

Make sure to refresh the node.js express api every minute with the latest timestamp available

I'm currently working on setting up a Node.js Express API to expose a MySQL table. Everything is working fine except for the part where I need to filter data by a current timestamp and update it every few minutes. I've tried using setInterval but ...

Tips for modifying Apache configuration using a PHP file

I have a server without any control panel. Currently, I am attempting to create a file that will enable me to add subdomains to my website by modifying the Apache config file and named zones. However, I do not possess the necessary permissions to edit the ...

Can you provide the XPath query to extract an href link from any website?

Looking to retrieve social links from the following URL: Check out Mahesh Waghmare's profile picture below: Member Since: October 6th, 2012 Pune, Maharashtra, India Wordpress Developer Connect with me on: https://www.facebook.com/mwaghmare7 ...

PHP TypeForm JSON submission

I am new to using JSON, so please forgive me if this is a basic question. A webhook has been set up to send me a JSON Post (Example Below) - I aim to extract the two answers from "text":"250252" & {"label":"CE"} { "event_id": "1", "event_type": " ...

Is it possible to reset the text within the text box when the form is being submitted using the load() ajax function?

I am working on implementing a comment feature where the data entered in the form is appended and displayed after submission. Here is my HTML form: <table> <tr><td>Name :</td><td> <input type="text" id="name"/></td&g ...

What is the best way to convert every database field into a public variable in PHP?

After running the query below, I have retrieved all database fields: "SHOW COLUMNS FROM admin" Now I am curious about how to convert each field into a public variable within a class structure since I am working with object-oriented PHP. My first step i ...

Is it possible to insert varied data into two separate tables using distinct INSERT statements within nested IF conditions?

I am currently facing an issue with inserting data into two different tables in my system. The first table, orders, is storing an overview of the order while the second table, order_item, is meant to store specific item data like quantity and product id. T ...

The MySQL error wreaks havoc on the Node.js server, causing it to

Whenever there is an error or exception coming from MySQL, my nodejs server ends up crashing. This is the code snippet from my backend where I tried using if-else in the query function to handle the response, but it still crashes the server. Even with try ...

Execute a function for every parameter in the query string

My query string is designed as follows: dinnerPlate=white&lunchPlate=purple&cup=black In addition, I have an array that stores all of the permissible colors.. $availableColors = array("white","black","red","blue","green","pink"); The task at ha ...