My php script isn't sending my information to my database

I am not getting any errors in my php script,  but my information  isn't getting sent to my database, and i can't figure it out.

I am attaching a snap shot of my database and  the files
 database image signupA.php
 viewprofile.php
 login.php
 index.php
imagekrazyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ajones2600flCommented:
You never check the return value to see if there was an error. In your code you have the following:

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

        $query = "INSERT INTO cool_people (userName, password,joinDate,firstname, lastname, gender, birthdate, state,city, town,picture ) VALUES ('$userName', SHA('$password'), NOW())";

            echo"$query";

        mysqli_query($query);


You never check the return value of mysqli_query($query) to see if it errors out. You just print out the query itself. You need to check for TRUE or FALSE. TRUE is success and FALSE is failure. If you get a FALSE, you can then retrieve the error. Or just cut and paste the print out from the echo into mysql navigator and see what error you are getting.

Ex. if (mysqli_query($query)== TRUE) {
   //success
   .....
} else {
   //failed
   .....
}
0
ajones2600flCommented:
Just a follow-up SHA has been hacked you should use SHA2 instead... Just a heads up.
0
imagekrazyAuthor Commented:
I still can't get it, I made the changes and its still not sending the information to my database
 signupA.php
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

Lukasz ChmielewskiCommented:
I wonder if this is related to your
    $username = mysqli_real_escape_string(trim($_POST['userName']));
case sensitive data, your username in input is "username", not "userName", use
    $username = mysqli_real_escape_string(trim($_POST['username']));
0
imagekrazyAuthor Commented:
I have username as userName  as one of the fields  so if i change it to username do i have to change it in the table also?
0
ajones2600flCommented:
No you do not have to change it in the table, just in your php code. What do you get on the echo to the screen. Use $username in the values part of the sql statement.
0
imagekrazyAuthor Commented:
I get this:
You must enter all of the sign-up data, including the desired password twice.[

its not registering any information in my database, it   just keep spitting out that echo statement,, and i also fixed the $username.
0
Lukasz ChmielewskiCommented:
try with this code in signupA.php, there were few errors

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Cool people - fun stuffp</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h3>cool people - fun stuff</h3>

<?php
  error_reporting(E_ERROR);
  require_once('appvars.php');
  require_once('connectvars.php');

  // Connect to the database
  $dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
                            //host  username   password  database name
  //print_r($_POST);                            
  //if(!empty($_POST)) echo"posted";
                            
  if (!empty($_POST)) {
  
    // 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(trim($_POST['password2']));

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

      // Make sure someone isn't already registered using this username
      $query = "SELECT * FROM cool_people WHERE userName = '$username'" ;
	  //echo"$query";
      $data = mysqli_query($query);
      if (mysqli_num_rows($data) == 0) {
        // The username is unique, so insert the data into the database
        $query = "INSERT INTO cool_people (userName, password,joinDate) VALUES ('$username', SHA('$password1'), 'NOW()')";
		echo"$query";
        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="login.php">log in</a>.</p>';

        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 use a different address.</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 Mismatch.</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <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>
</body> 
</html>

Open in new window

0
imagekrazyAuthor Commented:
WOW >>>WOW  I can't  believe it  you did it!!

okay it said it is;
 cool people - fun stuff
INSERT INTO cool_people (userName, password,joinDate) VALUES ('minisamuel', SHA('rachel'), 'NOW()')

Your new account has been successfully created. You're now ready to log in.

okay now here is the problem when it says to go to login  and i put the password in it  it don't acknowledge the  the new password but I know its stored now:)

here is the login script
 login.php
0
Lukasz ChmielewskiCommented:
ok, this is the login.php

<?php
  session_start();
  require_once('connectvars.php');

  // Start the session


  // Clear the error message
  $error_msg = "";

  // If the user isn't logged in, try to log them in
  if (!isset($_SESSION['user_id'])) {
	  header('HTTP/1.1 401 unauthorized');
	  header('WWW-Authoricate: Basic realm="cool_people"');
	  }
	  
    if (isset($_POST)) {
      // Connect to the database
      $dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);

      // Grab the user-entered log-in data
      $username = mysqli_real_escape_string($dbc, trim($_POST['username']));
      $password = mysqli_real_escape_string($dbc, trim($_POST['password']));
     // $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
	  
      if (!empty($username) && !empty($password)) {
        // Look up the username and password in the database
        $query = "SELECT userid, userName FROM cool_people WHERE userName = '$username' AND password = SHA('$password')";
        $data = mysqli_query($dbc, $query);

        if (mysqli_num_rows($data) == 1) {
          // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page
          $row = mysqli_fetch_array($data);
          $_SESSION['user_id'] = $row['userid'];
          $_SESSION['username'] = $row['userName'];
          setcookie('user_id', $row['user_id'], time() + (60 * 60 * 24 * 30));    // expires in 30 days
          setcookie('username', $row['username'], time() + (60 * 60 * 24 * 30));  // expires in 30 days
          $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
          header('Location: ' . $home_url);
        }
        else {
          // The username/password are incorrect so set an error message
          $error_msg = 'Sorry, you must enter a valid username and password to log in.';
        }
      }
      else {
        // The username/password weren't entered so set an error message
        $error_msg = 'Sorry, you must enter your username and password to log in.';
      }
    }
  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>fun stuff</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h3>cool people - Log In</h3>

<?php
  // If the session var is empty, show any error message and the log-in form; otherwise confirm the log-in
  if (empty($_SESSION['user_id'])) {
    echo '<p class="error">' . $error_msg . '</p>';
?>

  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend>Log In</legend>
      <label for="username">Username:</label>
      <input type="text" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br />
      <label for="password">Password:</label>
      <input type="password" name="password" />
    </fieldset>
    <input type="submit" value="Log In" name="submit" />
  </form>

<?php
  }
  else {
    // Confirm the successful log-in
    echo('<p class="login">You are logged in as ' . $_SESSION['user_name'] . '.</p>');
  }
?>

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imagekrazyAuthor Commented:
Hello again, its  echoing the  this
Sorry, you must enter your username and password to log in.

so it means its not reading the new password username:(
0
imagekrazyAuthor Commented:
thanks, and i will try to figure out the login page.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.