In a user creation form I have one element which is a drop down list where a role_type (i.e admin) can be assigned to the user.
Im not sure how to extract the value from the drop down and set it in the 'user' table because the table in the database takes a number however the user will select the value from the drop down.
The table the drop down is populated from only has two columns 'RoleTypeCode' which is auto incremented and 'Role_Title' which is the column used to populate the drop down.
The table i wish to update is referencing the RoleTypeCode.
USER: (UserRecordID(PK - AutoIncrement), Forename, Surname, Email, RoleTypeCode(FK))
Role_Type: (RoleTypeCode(PK - AutoIncrement), Role_Title)
So far i have:
$forename = $_POST['Forename'];
$surname = $_POST['Surname'];
$email = $_POST['Email'];
$role_title = $_POST['Role_Title'];
/*** connect to database ***/
include "db_conx.php";
try
{
$db_conx = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$db_conx->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insertUser = $db_conx->prepare("INSERT INTO user (Forename, Surname, Email, Role_TypeCode ) VALUES (:forename, :surname, :email, :role_title )");
/*** bind the parameters ***/
$insertUser->bindParam(':forename', $forename, PDO::PARAM_STR);
$insertUser->bindParam(':surname', $surname, PDO::PARAM_STR);
$insertUser->bindParam(':email', $email, PDO::PARAM_STR);
$insertUser->bindParam(':role_title', $role_title, PDO::PARAM_STR);
/*** execute the prepared statement ***/
$insertUser->execute();
/*** success message ***/
$message = 'New user added';
}
catch(Exception $e)
{
/*** check if the email already exists ***/
if( $e->getCode() == 23000)
{
$message = 'This email has already been registered';
}
else
{
/*** fail message incase something went wrong ***/
$message = 'Unable to process your request. Please try again later';
}
}
not sure how to cater for role_title
any help would be much appreciated!! :)
UPDATE: the process I'm looking for is after a user hits the submit button. Trying to extract the information from the drop down and set it in the users table. The code above is for the submit file once a user has clicked 'submit'