Jump to content

Update only half working


scottybwoy

Recommended Posts

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?

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.