Hey, I have a field called STATUS and it is either 1 to show or 0 to hide. My code is below. I am using an edit in place editor with jQuery. Everytime you update it creates a new ROW which I want, but I want only the new one to have STATUS = 1 and the others to 0. Any ideas on how I would do that?
<?php include '../../inc/config.inc.php'; $temp = explode('_', $_REQUEST['element_id'] ); $field = $temp[0]; $id = $temp[1]; $textboxval = stripslashes(mysql_real_escape_string(preg_replace('/[\$]/','',$_REQUEST['update_value']))); $query = 'INSERT INTO notes ($field,status,date,c_id) VALUES ('$textboxval','1',NOW(),'$id')'; mysql_query($query); echo($_REQUEST['update_value']); ?>
I am not sure exactly what you mean – do you want to make all the entries except the new one have status = 0? If so, just issue an update before the insert:
However, I should also note that you have a potential SQL injection to worry about. By stripping slashes after applying ‘mysql real escape string’, you are potentially allowing someone to put text in your SQL statement that will execute an arbitrary SQL statement.