scottybwoy Posted January 12, 2007 Share Posted January 12, 2007 Hi again,I have an update query that works but does not insert into one specific field. In my database the table that I am entering the data into has a text field called compNote, and my Update sql query looks fine the name matches just doesn't hold the data. And returns no errors either. Here's my code :[code]<?php function updateCust($data_array, $update) { static $colvals; $custId = $data_array["custId"]; $this->appCon(); $sql = "SELECT * FROM customers WHERE custId = '" . $custId . "'"; $row = mssql_fetch_assoc(mssql_query($sql)); array_shift($update); array_pop($update); $diff = array_diff_assoc($update, $row); if (!empty($diff)) { $colvals = ""; foreach ($diff as $k => $v) { $colvals.= $k . " = '" . $v . "', "; } $colvals = substr($colvals, 0, -2); $sql = "UPDATE customers SET " . $colvals . " WHERE custId = '" . $custId . "'"; echo $sql; $this->appCon(); mssql_query($sql); } else { echo "Nothing to change"; } unset($data_array); }?>[/code]This is the echo of the sql statement :"UPDATE customers SET compNote = 'this data is not getting stored' WHERE custId = 'MRI000'"Some other examples :UPDATE customers SET country = 'will', compNote = 'wont' WHERE custId = 'TES000'This is interesting though :UPDATE customers SET country = 'does', compNote = '' WHERE custId = 'TES000'Can't see why it always has compNote there tho? Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/33888-update-only-half-working/ Share on other sites More sharing options...
scottybwoy Posted January 12, 2007 Author Share Posted January 12, 2007 I found my problem is that it is actually storing the data but just not displaying it, so when it has no value it tries to store that too.However the the array of data sent to the form to be displayed is queried direct from the db in an assoc array. then the field values request the valid field in the same way it does all the rest like so.[code]<?php<label for='tel'>Telephone :</label><input type="text" id='tel' name='tel' value='<?php echo $data_array["tel"]; ?>' size=22% MAXLENGTH="50" ONCHANGE="validateTelnr(this, 'inf_telnr');" tabindex='8' class='required inputR' />//Telephone works<div> <label for='compNote' class='compNote'>Notes :</label> <textarea type="text" rows='5' id='compNote' name='compNote' value='<?php echo $data_array["compNote"] ?>' tabindex='14'></textarea></div>// compNote doesn't?>[/code]Any suggestions is there a difference in the way text area works to other input fields? Quote Link to comment https://forums.phpfreaks.com/topic/33888-update-only-half-working/#findComment-159091 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 textareas dont work the same way as normal input fields. try this:[code] <textarea rows='5' id='compNote' name='compNote' tabindex='14'><?php echo $data_array["compNote"] ?></textarea>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33888-update-only-half-working/#findComment-159096 Share on other sites More sharing options...
scottybwoy Posted January 12, 2007 Author Share Posted January 12, 2007 wikid thanks Quote Link to comment https://forums.phpfreaks.com/topic/33888-update-only-half-working/#findComment-159220 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.