tags:

views:

45

answers:

2

good evening all,

i have been trying to update records but can't seem to code in the substr command to extract certain details from a string.

i have a doa (date of accident) text field currently working with kelvinluck's jquery datepicker plugin.

originally the single doa textfield was split into three drop downs... namely: doaDay, doaMonth, doaYear. each had their own field in the database as well.

but i've decided to unify the doaDay, doaMonth, doaYear into one single field... called doa and us kevinluck's jquery datepicker plugin.

now as i have well over a 100 records in my database using the doaDay,doaMonth,doaYear fields i decided to use the substr command in order to extract the dd (doaDay), mm (doaMonth) and yyyy (doaYear) from the new updated dd/mm/yyyy (field).

this was my solution when INSERTING the database:

$doa = $_POST['doa'];
$doaDay = substr($doa, 0, 2);
$doaMonth = substr($doa, 4, 5);
$doaYear = substr($doa, 7, 10);

then the record was inserted after POST.

mysql_query("INSERT INTO tbl_personalinjury (`doaDay`, `doaMonth`, `doaYear`)                          
VALUES ('$doaDay', '$doaMonth', '$doaYear')");

now the problem arises when im trying to update the record. as a completely new method is used and i am having difficulty implementing it. here is what i have so far.

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
  $updateSQL = sprintf("UPDATE tbl_accident SET doaDay=%s, doaMonth=%s, doaYear=%s, WHERE id=$client_id",
                       GetSQLValueString($_POST['doaDay'], "text"),
                       GetSQLValueString($_POST['doaMonth'], "text"),
                       GetSQLValueString($_POST['doaYr'], "text"),

how do i go about extracting dd, mm, yyyy from the doa textfield and assigning the values to $doaDay, $doaMonth, and $doaYear respectively. i would appreciate any advice.

God bless.

+1  A: 

Why not just do $doa_bits = explode('/', $doa); . This should give you an array with 3 items, $doa_bits[0] would be the day, $doa_bits[1] would be the month and $doa_bits[2] would be the year.

Nick Shepherd
jeansymolanza
`GetSQLValueString($doa_bits[0], "text")`, etc...
Nick Shepherd
i have posted the edited code below as a seperate answer as im not sure how to use the formatting within this box.
jeansymolanza
it works perfectly thanks
jeansymolanza
A: 
    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form")) {
$doa_bits = explode('/', $doa)
      $updateSQL = sprintf("UPDATE tbl_accident SET doaDay=%s, doaMonth=%s, doaYear=%s, WHERE id=$client_id",
                           GetSQLValueString($doa_bits[0], "text"),
                           GetSQLValueString($doa_bits[1], "text"),
                           GetSQLValueString($doa_bits[2], "text"),

is this what you are alluding to good sir?

jeansymolanza
yup, glad it worked for you :)
Nick Shepherd