Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use substr on MySQL update record?
    primarykey
    data
    text
    <p>I have been trying to update records but can't seem to code in the substr command to extract certain details from a string.</p> <p>I have a "doa" (date of accident) text field currently working with kelvinluck's jquery datepicker plugin.</p> <p>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.</p> <p>But I've decided to unify the doaDay, doaMonth, doaYear into one single field, called doa and us kevinluck's jquery datepicker plugin.</p> <p>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).</p> <p>This was my solution when INSERTING the database:</p> <pre><code>$doa = $_POST['doa']; $doaDay = substr($doa, 0, 2); $doaMonth = substr($doa, 4, 5); $doaYear = substr($doa, 7, 10); </code></pre> <p>Then the record was inserted after POST.</p> <pre><code>mysql_query("INSERT INTO tbl_personalinjury (`doaDay`, `doaMonth`, `doaYear`) VALUES ('$doaDay', '$doaMonth', '$doaYear')"); </code></pre> <p>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.</p> <pre><code>if ((isset($_POST["MM_update"])) &amp;&amp; ($_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"), </code></pre> <p>How do I go about extracting dd, mm, yyyy from the doa textfield and assigning the values to $doaDay, $doaMonth, and $doaYear respectively?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload