Link to home
Start Free TrialLog in
Avatar of imagekrazy
imagekrazy

asked on

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
 User generated image signupA.php
 viewprofile.php
 login.php
 index.php
Avatar of ajones2600fl
ajones2600fl

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
   .....
}
Just a follow-up SHA has been hacked you should use SHA2 instead... Just a heads up.
Avatar of imagekrazy

ASKER

I still can't get it, I made the changes and its still not sending the information to my database
 signupA.php
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']));
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?
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.
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.
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

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
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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:(
thanks, and i will try to figure out the login page.