Ok Im sorry - I have been spending the last few days working on this, and Im stuck... and so I am asking for advice or fresh set of eyes to help me out here...
The code here has either been working or has been tested in the sql section of phpMyAdmin... some background, I have a db with two tables, users and roles. I am trying to insert a user into the users db (works 99% of the time...) and then after the user is created as long as there were no errors prior, then to create a row in the roles table and set the roles based on the user.... Seems simple but even though the queries work in the phpmyadmin and dont cause issue, the php code fails every time it is run... the user is created... and cannot access the rest of the site unless i manually add them to the roles table... Im sure that you can understand why I want to have this going when a user creates the login...
@ $query = "INSERT INTO users
(
Username , Password , pwsecret , emailAddress , Fname , Lname , Joined_Date
)
VALUES
(
'$uName' , '$encoded', '$salt' , '$email' , '$firstName' , '$lastName', CURRENT_TIMESTAMP
)";
ini_set('display_errors', 'On');
if (!mysqli_query($db,$query)){
$error_message = "There was a problem when attempting to add you as a user, please try again and if the issue persists please contact the webadmin.";
//clear vars for reuse::
$_POST = array(); //should stop data from persisting.
$uName = "";
$pw1 = "";
$pw2 = "";
$encoded = "";
$email = "";
$firstName = "";
$lastName = "";
include("partial/user/_register.php");
exit(); //jic something goes wrong we do not want to have the script resume.
}else{
//the following should add a newly generated user to the roles table.
$select="(SELECT userID FROM users WHERE Username = $uName)"; //sub query to return a user ID
$insert="INSERT INTO roles (userID , isAdmin , isMod , isFormerStaff , isUser , isBanned) VALUES ((SELECT userID FROM users WHERE Username = $uName;) , 0 , 0 , 0 , 1 , 0);"; //insert query to add user to roles table
//I tested this code in mysql phpmyAdmin and it worked with out error...
if (!mysqli_query($db,$insert)){
echo "User role not created - please add user manually.";
}
In the second query there is a select statement in the userID field this was done since I need it to get the userID of the last person to register, Bear also in mind that this is being run right after the user is generated, and assume that the tables are clean.
Any help you guys can show or the source the issue would be greatly appreciated.... I know its probably something that I missed... but i cannot see it..
Jesse Fender