Posted: Sat Feb 14, 2004 1:33 am
Thats only because of the global statement. Globals are really becoming a pain in the ass all of sudden for coding functions or any other situation needed such as what you coded up.. 
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
function addentry($data, $table) {
unset ($data["field1 in table"]);
unset ($data["field2 in table"]);
// do this for every field you wish to put data in and by doing it this way, the names of your fields must be the same for the names in your forms or this wont work, if it works at all
$query = "INSERT INTO ";
$column = "column title (";
$vars = "VALUES (";
foreach ( $data as $key => $value ) {
$column .= "`$key`, ";
$vars .= "'$value', ";
}
$column = rtrim($column, ", ");
$vars = rtrim($vars, ", ");
$query = $query . $column . ") " . $vars . ") ";
return $query;
}
?>Code: Select all
<form name='form1' method='post' action='$strPAGE'>Code: Select all
<form action=add.php name=info method=POST>Code: Select all
<?php
if(isset($info)) {
function addentry($data, $table) {
unset ($data["field1 in table"]);
unset ($data["field2 in table"]);
$query = "INSERT INTO ";
$column = "column title (";
$vars = "VALUES (";
foreach ( $data as $key => $value ) {
$column .= "`$key`, ";
$vars .= "'$value', ";
}
$column = rtrim($column, ", ");
$vars = rtrim($vars, ", ");
$query = $query . $column . ") " . $vars . ") ";
return $query;
}
}
?>