Hello all,
I have about 2 months experience working with php so please if you answer to my post try not to use too technical term or lingo only a season program would understand. I would appreciate that very much. Also English is not my native language, so please be warned lol. Just ask me to re-phrase my question if it make no sense to you.
my question:
I have a profile form which include a set of 3 fields used to enter a Canadian social insurance number. there are 9 number total. 3 numbers per field. this is necessary because I picked up a neath little javascript validation utility that verify if the SIN is genuine. So after the user enter the SIN I then concatenate the 3 fields into one and save it into my database with "-" separators.
Now I am scratching my head trying to figure out how to bring that concatenated sin number from the database back into the 3 original fields on the form when a user wants to update their profile. I think using the explode function will do that but I have problem finding a way to name the variable array that will be used to insert into the form.
i been trying to echo into the first input as a test and what I have doesnt' work.
Social Insurance Number <input type = "text" id = "S1" name="S1" size =" 3" maxlength = "3" onkeyup = "validate(this,2)" value=<?php if (isset($_POST['sin']) ){echo explode("-",$sin)['0']}?>>
<input type = "text" id = "S2" name="S2" size =" 3" maxlength = "3" onkeyup = "validate(this,3)">
<input type = "text" id = "S3" name="S3" size =" 4" maxlength = "3" onkeyup = "validate(this,3)">
this is how I concatenated my values:
$sin1 = $_POST['S1'];
$sin2 = $_POST['S2'];
$sin3 = $_POST['S3'];
$sin = $sin1 ."-". $sin2 ."-". $sin3;
this is my calling function:
$users->update_user($first_name, $middle_name, $last_name, $gender, $dob, $sin, $bio, $image_location, $user_id);
header('Location: settings.php?success');
exit();
This is my user update class
public function update_user($first_name, $middle_name, $last_name, $gender, $dob, $sin, $bio, $image_location, $id){
$query = $this->db->prepare("UPDATE `users` SET
`first_name` = ?,
`middle_name` = ?,
`last_name` = ?,
`gender` = ?,
`dob` = ?,
`sin` = ?,
`bio` = ?,
`image_location`= ?
WHERE `id` = ?
");
$query->bindValue(1, $first_name);
$query->bindValue(2, $middle_name);
$query->bindValue(3, $last_name);
$query->bindValue(4, $gender);
$query->bindValue(5, $dob);
$query->bindValue(6, $sin);
$query->bindValue(7, $bio);
$query->bindValue(8, $image_location);
$query->bindValue(9, $id);
try{
$query->execute();
}catch(PDOException $e){
die($e->getMessage());
}
}