Click here to Skip to main content
15,346,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Cpanel users database wont store data I am trying to input from a registration form from my website. It does acknowledge the account is being made and increments the usersId by 1 but it just wont store data like: FirstName, PhoneNumber etc. Any ideas?

Code is below:

Registration form code:

<pre lang="HTML">
<pre><!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <title>Registration Form</title>
  </head>
  <body class="registerbody">
    <img class="logoregister" src="images/logo.png" />
    <div class="registerformcontainer">
      <div class="titlestyle">Registration Form</div>
      <form action="signup.form.php" method="POST">
        <div class="inputform">
          <div class="userinputboxes">
            First Name:
            <input name="Fname" type="text" placeholder="Enter your First Name " required />
          </div>
          <div class="userinputboxes">
            Last Name:
            <input name="Lname" type="text" placeholder="Enter your Last Name " required />
          </div>
          <div class="userinputboxes">
            Enter User Name:
            <input name="USERname" type="text" placeholder="Enter your desired User name " required />
          </div>
          <div class="userinputboxes">
            Email:
            <input name="Email"
              value=""
              onchange="try{setCustomValidity('')}catch(e){}"
              type="email"
              placeholder="Enter your Email address "
              id="email"
              name="email"
              pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
              required
            />
          </div>
          <div class="userinputboxes">
            Phone Number:
            <input name="Pnum"
              type="text"
              placeholder="Enter your Phone Number "
              required
            />
          </div>
          <div class="userinputboxes">
            Date of Birth:
            <input name="Bdate" type="date" required />
          </div>
          <div class="userinputboxes">
            Password:
            <input
            name="Pass"
              type="password"
              placeholder="Enter your Password "
              required
            />
          </div>
          <div class="userinputboxes">
            Confirm Password:
            <input
            name="Passrepeat"
              type="password"
              placeholder="Confirm your Password"
              required
            />
          </div>
        </div>
        <div class="button">
          <input type="submit" value="Create account" />
        </div>
      </form>
    </div>


db.form.php code below:

PHP
<?php


$servername = "localhost";
$dbUsername = "woodrub1_user2";
$dbPass = "database12345";
$dbName = "woodrub1_ecommerce";

$conn = mysqli_connect($servername, $dbUsername, $dbPass, $dbName);


signup.form.php code below:

PHP
<?php

session_start();

include("db.form.php");


if($_SERVER['REQUEST_METHOD'] == "POST"){
  $Fname = $_POST['Fname'];
  $Lname = $_POST['Lname'];
  $USERNAME = $_POST['USERname'];
  $Email = $_POST['Email'];
  $Pnum = $_POST['Pnum'];
  $Bdate = $_POST['Bdate'];
  $Pass = $_POST['Pass'];
  $Passrepeat = $_POST['Passrepeat'];


  if (!empty($USERNAME) && !empty($PWD) && !is_numeric($USERNAME)){

    $query = "insert into users (usersFName, usersLName, usersEMAIL, usersUSERSNAME,usersPNUM, usersBDATE, usersPWD) values ('$usersFName', '$usersLName', '$usersEMAIL', '$usersUSERSNAME','$usersPNUM', '$usersBDATE', '$usersPWD')";
    mysqli_query($conn, $query);

    header("Location: FinalProjectHomePage.php");
    die;
  }
}


What I have tried:

Ive tried to swap variables and change $_POST but nothing seemed to work
Posted
Updated 23-Nov-21 11:32am
Comments
Richard Deeming 24-Nov-21 3:46am
   
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]
Richard Deeming 24-Nov-21 3:46am
   
You are storing passwords in plain text. Don't do that!
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even has built-in functions to help you do the right thing:
PHP: password_hash[^]
PHP: password_verify[^]
Richard Deeming 24-Nov-21 3:48am
   
Also, you're asking the users to confirm their password, but you never validate that the two values match. Either check that $Pass is the same as $Passrepeat, or remove the "confirm password" box from your form.
Bryan Woodruff 24-Nov-21 10:29am
   
I got it working guys! Thank you all so much, I was blind and realized it was something simple. Also yes I didnt do the passrepeat or passhashing function yet I just wanted to get storing of the data done.
Bryan Woodruff 24-Nov-21 10:30am
   
Also Richard , yes I have been reading about prepared statements Im still relatively new to this stuff

1 solution

Why don't the variable names which are being posted to...??

PHP
$Fname = $_POST['Fname'];
  $Lname = $_POST['Lname'];
  $USERNAME = $_POST['USERname'];
  $Email = $_POST['Email'];
  $Pnum = $_POST['Pnum'];
  $Bdate = $_POST['Bdate'];
  $Pass = $_POST['Pass'];
  $Passrepeat = $_POST['Passrepeat'];


...match the variable names which are being used in the INSERT statement?


PHP
$query = "insert into users (usersFName, usersLName, usersEMAIL, usersUSERSNAME,usersPNUM, usersBDATE, usersPWD) values ('$usersFName', '$usersLName', '$usersEMAIL', '$usersUSERSNAME','$usersPNUM', '$usersBDATE', '$usersPWD')";


1. The user is posting the values from the web page
2. You are getting those values from the POSTed data and storing in variables
3. Then the INSERT statement should be using those values via the variables, right?

But $Lname isn't used in the INSERT statement.
Instead $usersLName is used there.
Why is that?
If you use $Lname (and all the others which are read from $_POST) in the Insert statement I believe it may work.
   
v2

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