Jump to content

PHP signup is not working


sandia82

Recommended Posts

I created this signup page, but it is not connecting to the database. What am I missing?

 

Here is the coding I have.

 

<?php

  // Insert the page header

  $page_title = 'Sign Up';

  require_once('header.php');

 

  require_once('appvars.php');

  require_once('connectvars.php');

 

  // Connect to the database

  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

 

  if (isset($_POST['submit'])) {

    // Grab the profile data from the POST

    $username = mysqli_real_escape_string($dbc, trim($_POST['Username']));

    $password1 = mysqli_real_escape_string($dbc, trim($_POST['Password1']));

    $password2 = mysqli_real_escape_string($dbc, trim($_POST['Password2']));

 

    if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {

      // Make sure someone isn't already registered using this username

      $query = "SELECT * FROM UCT_MembersInfo WHERE username = '$username'";

      $ = mysqli_query($dbc, $query);

      if (mysqli_num_rows($data) == 0) {

        // The username is unique, so insert the data into the database

        $query = "INSERT INTO UCT_MembersInfo (Username, Password, CreateDate) VALUES ('$Username', SHA('$Password1'), NOW())";

        mysqli_query($dbc, $query);

 

        // Confirm success with the user

        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="index.php">log in</a>.</p>';

 

        mysqli_close($dbc);

        exit();

      }

      else {

        // An account already exists for this username, so display an error message

        echo '<p class="error">An account already exists for this username. Please create a different username.</p>';

        $username = "";

      }

    }

    else {

      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';

    }

  }

 

  mysqli_close($dbc);

?>

 

  <p>Please enter your username and desired password to sign up to the Ultimate Casting Team Site.</p>

  <form method="post" action="<?php echo $_SERVER['QUERY_STRING']; ?>">

    <fieldset>

      <legend>Registration Info</legend>

      <label for="username">Username:</label>

      <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br />

      <label for="password1">Password:</label>

      <input type="password" id="password1" name="password1" /><br />

      <label for="password2">Password (retype):</label>

      <input type="password" id="password2" name="password2" /><br />

    </fieldset>

    <input type="submit" value="Sign Up" name="submit" />

  </form>

 

<?php

  // Insert the page footer

  require_once('footer.php');

?>

 

Link to comment
https://forums.phpfreaks.com/topic/175316-php-signup-is-not-working/
Share on other sites

Here is the error that I am getting:

Parse error: syntax error, unexpected '=', expecting T_VARIABLE or '$' in /home8/ultimaz7/public_html/signup.php on line 21

 

I was working on it yesterday and it  would create the username and password and it told me: "You must enter all of the sign-up data, including the desired password twice."

 

The site is http://www.ultimatecastingteam.com/

Now I'm getting these two errors:

 

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'DB_HOST' (1) in /home8/ultimaz7/public_html/signup.php on line 10

 

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home8/ultimaz7/public_html/signup.php on line 44

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.