1

I'm inserting into MySQL using PHP, the Code goes through but when I query the database I find nothing in my Database. I can't figure out whats happening. I have five fields in my Db(ID,username,email,password,salt). Below is my PHP code.

<?php include 'db_connect.php'; include 'functions.php'; $password = $_POST['password']; $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true)); $password = hash('sha512', $password.$random_salt); if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password,salt) VALUES (?, ?, ?, ?)")) { $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt); $insert_stmt->execute(); echo 'User added'; } else { echo 'Error couldnt add the user, Try again'; } ?> 

And Below is my Form used for the registration.

 <form id="form1" name="form1" method="post" action="Registration Process.php"> <table width="373" height="130" border="1"> <tr> <td width="180" height="27">Username (Name &amp; Surname)</td> <td width="140"><label for="username"></label> <input type="text" name="username" id="username" /></td> </tr> <tr> <td height="23">Email</td> <td><label for="email"></label> <input type="text" name="email" id="email" /></td> </tr> <tr> <td height="22">Password</td> <td><label for="password"></label> <input type="text" name="password" id="password" /><label for="salt"> </label> </td> </tr> <tr> <td height="22">Salt</td> <td><input type="text" name="salt" id="salt" /></td> </tr> <tr> <td height="22">Click To register member</td> <td><input type="submit" name="register" id="register" value="Submit" /></td> </tr> </table> <p>&nbsp;</p> <!-- end .content --> </form> 
7
  • 2
    is this correct ?? action="Registration Process.php" with a space ? Commented Feb 5, 2013 at 8:19
  • 4
    how do all the other variables get populated? like $username, $email etc. - I don't see them being set in your code... also, you're not catching errors in your $insert_stmt->execute() function - see example 3 on this page for more info Commented Feb 5, 2013 at 8:23
  • @swapnesh yes I think its correct, But I'l change it for arguments sake and also change the file name. thanx Commented Feb 5, 2013 at 8:31
  • @ZathrusWriter oh I forgot to do that via the post method let me add it and I'l get back to you... Commented Feb 5, 2013 at 8:32
  • @ZathrusWriter thanx a lot its now working, It was because it wasnt getting the $username and $email values...I now added them it works. Thanx a lot :) Commented Feb 5, 2013 at 8:45

1 Answer 1

1

You might not be getting your $username, $email and other variables from POST array in your code.

Furthermore, you're not catching errors in your $insert_stmt->execute() function - see example 3 on this page for more info.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.