Can I see an example of something..
Moderator: General Moderators
- Michael 01
- Forum Commoner
- Posts: 87
- Joined: Wed Feb 04, 2004 12:26 am
-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
perhaps:
The var $data is your $_POST variables made into a array for transfering the values into the DB, let me know if it works.
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;
}
?>-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
lets try this then to just test some things:
Change to:
make a add.php and paste this code:
Let me know how this works
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;
}
}
?>and like I said
the unset ($data["field1 in table"]);
by field1 in table is the name of the field in your SQL table, and that name must be the same for the name your are assigning the variable in the <form> tags or this wont work peroid.
so <input name='date' type='text' value='$date' maxlength='20'>
would look like
unset ($data["date"]);
date being the title of the field in the table as well as the title assigned variable.
the unset ($data["field1 in table"]);
by field1 in table is the name of the field in your SQL table, and that name must be the same for the name your are assigning the variable in the <form> tags or this wont work peroid.
so <input name='date' type='text' value='$date' maxlength='20'>
would look like
unset ($data["date"]);
date being the title of the field in the table as well as the title assigned variable.
-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact: