Click here to Skip to main content
15,886,088 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php 
$yourFname = $_POST['firstname'];
$yourLname = $_POST['lastname'];
$yourAge = $_POST['age'];
$yourHeight= $_POST['height'];
$yourWeight= $_POST['weight'];
$yourEmail= $_POST['email'];
$yourCPnumber= $_POST['cpnumber'];
$yourPassword= $_POST['password'];

$conn = new mysqli('localhost', 'root', '','regisdata');

if($conn->connect_error){
    die('Connection Failed : ' .$conn->connect_error);
}
else
{
    $stmt = $conn->prepare("Insert into user_info(first_name, last_name, age, height, weight, email, cp_number, password) values (?, ?, ?, ?, ?, ?, ?, ?,)");
    if($stmt !== FALSE){
    $stmt->bind_param("ssiiisss", $yourFname, $yourLname, $yourAge, $yourHeight, $yourWeight, $yourEmail, $yourCPnumber, $yourPassword);
    
    $stmt->execute();
         $stmt->close();
    $conn->close();
    }
    echo "Success";

}
So im new to web development this is my first attempt to connect my form to the database, but it frustrate me that my php script dont have an error and still the data that i input from the form is not showing to the database 
 <pre lang="PHP">



What I have tried:

I didn't try other method to connect php to the database because i dont know what is good or bad method to try on plus im looking for a simple tutorial for me to understand well. So if there is a wrong to my code im looking forward for your suggestion to fix this problem. THANK YOU IN ADVANCE
Posted
Updated 5-Aug-23 16:12pm

1 solution

Try removing the training comma:
$stmt = $conn->prepare("Insert into user_info(first_name, last_name, age, height,
weight, email, cp_number, password) values (?, ?, ?, ?, ?, ?, ?, ?,)");
                                                                  ^
                                                                  |
Chances are that's causing a problem at MySql which you aren't handling.
 
Share this answer
 
Comments
oceanotrash 18-Apr-20 10:38am    
Thank you OriginalGriff sorry im late to response
OriginalGriff 18-Apr-20 10:52am    
No problem - I got one "thank you" 3 years after I posted the solution! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900