Jump to content

Recommended Posts

 

Hi there,

 

No matter what "username" and "password" type in my machine to test my code, the program replays: An account already exists for this username.

 

that's the code:

<?php

  require_once('connectvars.php');

 

  // Connect to the database

  $dbc = mysqli_connect('localhost', 'root', 'zambullo', 'entrepreneurial groups')

    or die ('Error connecting to MySQL server');

 

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

    // Grab the profile data from the POST

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

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

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

 

    if (!empty($username) && !empty($password) && !empty($repeatpassword) && ($password == $repeatpassword)) {

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

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

      $result = mysqli_query($dbc, $query);

      if ($result = $mysqli->query) {

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

        $query = "INSERT INTO entrepreneurialgroups _user (username, password) VALUES ('$username', '$password')";

        $row_cnt = $result->num;

 

        // Confirm success with the user

        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.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.</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);

?>

 

I appreciate your help

$query = "INSERT INTO entrepreneurialgroups _user (username, password) VALUES ('$username', '$password')";

What is that? You have 2 different tables? And is there a space or not?

 

Also, you shouldn't trim passwords. What if someone decided to start a password with a space? Is that illegal?

 

Now to the problem:

if ($result = $mysqli->query) {

What is $mysqli? That's not a defined variable/object.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.