PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function updateContent($id, $table){
if(isset($_POST['save'])) {
$title = $_POST['title'];
$abstract = $_POST['abstract'];
$body = $_POST['body'];
if(!get_magic_quotes_gpc()) {
$title = addslashes($title);
$body = addslashes($body);
$abstract = addslashes($abstract);
}
$query = "UPDATE " . $table . " SET title = '$title', abstract='$abstract', body = '$body' WHERE id = '$id'";
mysql_query($query) or die('Error : ' . mysql_error());
}
}
In theory what I want to happen is to add all the rows to be affected in the beginning.
I'm making up the syntax but something like "function updateContent($id, $table, row[fname, lname]);" Each item in the row array would end up in $_POST and addslashes().
I'm not sure what your example function declaration is actually describing. Unless I understand wrong, the final declaration would be a maximum of three required arguments where the third is an array of named elements. Is this correct?
If so, I'm not sure I understand what the question is then.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '19103']}', city ='{$_POST['Philadelphia']}' WHERE id='1'' at line 1
Is it not putting '{$_POST[' infront of the first item? The same as when you use the implode function?
All right. It sets exactly one field in the record and therefore has nothing to do with
psurrena wrote:I want to be able to use the function to update all the fields in the database declared in parentheses, whether it's one or eight or twenty.
but if it solves your problem and you're happy so are we
You realize you are setting city field to the literal string '{$_POST['Philadelphia']}'.
Its not using the value in $_POST.
By which I mean, when you query that record and field back again you will get '{$_POST['Philadelphia']}'. If that is what you want (its not impossible, but unlikely) we are all happy.