No display of data

  1 <!DOCTYPE html>
  2 <html>
  3 <head>
  4 <meta charset="utf-8">
  5 <title>Registration</title>
  6 <link rel="stylesheet" href="styles.css" /> 
  7 </head>
  8 <body>
  9 
 10 
 11 <?php
 12 require('header_new.php');
 13 require('config.php');
 14 ?>
 15 
 16 <div class="form">
 17 <h1>Registration</h1>
 18 <form name="registration" action="" method="post">
 19 <input type="text" name="username" placeholder="Username" required />
 20 <input type="submit" name="Check" value="Check" />
 21 </div>
 22 <?php
 23 if (isset($_POST['submit'])){
 24 
 25         $username=$_POST['username'];
 26           $username = stripslashes($_REQUEST['username']);
 27           $username = mysqli_real_escape_string($conn,$username);
 28 
 29           $sql_data = "SELECT * FROM login WHERE username='$username'";
 30           $result_data=mysqli_query($conn, $sql_data);
 31           $row_data = mysqli_fetch_assoc($result_data);
 32 
 33           if ($row_data == true) {
 34                  echo "User: " .$row_data['username'].  "  Exists !";
 35                 exit();
 36           } else {
 37           echo "No User!";
 38           }
 39         }
 40      ?>
 41    </body>
 42    </html>

I’m going to guess by the title that you mean neither of the echo … statements are displaying anything. You need to specifically state what result you are or are not getting. “No display of data” could mean either 1) a blank page, 2) you are getting “User: Exists !”, without the $row_data value, or 3) neither of the echo statements is outputting anything.

The reason for this problem is because there is no form field with the name ‘submit’ that the php code is testing for. You have two form fields. One is named ‘username’. The second is named ‘Check’.

Checking for the form submission should be at the top of the page before the HTML or on a separate php file. That includes some validation of fields that can’t be done in HTML.

Here’s an example of my registration page for one of my websites:

    <div id="registrationPage">
        <form class="registerForm" action="" method="post" autocomplete="on">

            <h1><?php echo (isset($message)) ? $message : 'Register'; ?></h1>
            <p><?php echo (isset($errPassword)) ? $errPassword : "Please fill in this form to create an account."; ?></p>
            <hr>

            <label for="fullName"><b>Full Name</b></label>
            <input id="fullNamae" type="text" placeholder="Enter Full Name" name="data[fullName]" autofocus required>
            
            <label for="username"><b>Username <span class="unavailable"> - Not Available, please choose a different one.</span></b></label>
            <input id="username" type="text" placeholder="<?php echo (isset($statusUsername) && $statusUsername) ? "Username is not available, please re-enter!" : "Enter Username"; ?>" name="data[username]" value="<?php echo (isset($data['username'])) ? $data['username'] : null; ?>" required>

            <label for="email"><?php echo (isset($errEmail)) ? $errEmail : "<b>Email</b>"; ?></label>
            <input type="email" placeholder="Enter Email" name="data[email]" value="<?php echo (isset($data['email'])) ? $data['email'] : null; ?>" required>

            <label for="psw"><b>Password <span class="recommendation">recommendation at least (8 characters long, 1 uppercasse letter, 1 number, and 1 special character)</span></b></label>
            <input id="password" type="password" placeholder="Enter Password" name="data[password]" required>

            <label for="psw-repeat"><b>Repeat Password</b></label>
            <input type="password" placeholder="Repeat Password" name="data[repeatPassword]" required>
            <hr>

            <p>By creating an account you agree to our <a href="termsPolicy.php">Terms & Privacy</a>.</p>
            <input type="submit" name="submit" value="enter" class="registerbtn">


            <div class="signin">
                <p>Already have an account? <a href="login.php">Sign in</a>.</p>
            </div>
        </form>

Notice how I don’t check any of the form fields? That’s because I do it somewhere else.

Thanks changed (isset($_POST[‘username’])) and it worked
:smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service