How to use substr on MySQL update record?
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'], "te开发者_高级运维xt"),
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?
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.
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?
精彩评论