Hi,
I'm not a total newb to php, but I do have my short comings... and this is a BIG one... can someone please help? I hope I give enough info.
OK... I have a download script, and want the admin to be able to add various fields to the script automatically... just by typing in a name in the 'Add Field' function.... everything works in admin, and in the script, up to the point of adding a value to the field itself. I need it to pass the vars to the function that puts it into the DB. I'm using PHP Nuke, if anyone notices the DB calls and such... OK, here is some info....
This is how I have it set up in admin, to add the fields:
function field_add_save($fname) {
global $prefix, $dbi;
$fname = stripslashes(FixQuotes($fname));
if ($fname != "") {
$fname = ereg_replace(" ","_",$fname);
sql_query("insert into ".$prefix."_downloads_field values (NULL, '$fname')", $dbi);
$result_delete = mysql_query("drop table if exists ".$prefix."_downloads_field_new_".$fname."");
if (!$result_delete) {
print mysql_error();
die();
}
$result_create = mysql_query("create table ".$prefix."_downloads_field_new_".$fname." (
lid int(13) NOT NULL default '',
".$fname."_value varchar(255) DEFAULT '' NOT NULL
)");
if (!$result_create) {
print mysql_error();
die();
}
Header("Location: admin.php?op=ns_edl_field#new");
} else {
Header("Location: admin.php?op=ns_edl_field_add#add");
}
}
This creates a new table for each new field... I just put in the error calls to help debug the thing...
This is how I show the fields in the script:
function list_nfields($lid) {
global $prefix, $dbi, $module_name;
$result_new = sql_query("select * from ".$prefix."_downloads_field", $dbi);
while(list($fid, $fname) = sql_fetch_row($result_new, $dbi)) {
$result_value = sql_query("select ".$fname."_value from ".$prefix."_downloads_field_new_".$fname." where lid='$lid'", $dbi);
list($fname_value) = sql_fetch_row($result_value, $dbi);
$fname = ereg_replace("_"," ",$fname);
if ($fname_value != "") {
echo "<b>$fname:</b> $fname_value<br>";
}
}
}
Any field with value, attached to the specific download id ($lid) will show with the actual download.
Again, EVERYTHING works great... EXCEPT for passing multiple fields... I need to pass them from the Add Download function, to the Add function, where the values are inserted into the DB. If I add a value to any given field manually, the output works perfect... I just need it to be able to do it through the script, for the user submitting a download.
OK, now this is how I print out the new fields to the user's form:
function add_nfields() {
global $prefix, $dbi, $module_name;
$result_new = sql_query("select * from ".$prefix."_downloads_field", $dbi);
while(list($fid, $fname) = sql_fetch_row($result_new, $dbi)) {
$result_value = sql_query("select ".$fname."_value from ".$prefix."_downloads_field_new_".$fname."", $dbi);
list($fname_value) = sql_fetch_row($result_value, $dbi);
$fname = ereg_replace("_"," ",$fname);
echo "<tr><td align=\"left\"><b>$fname:</b><br>";
echo "<input type=\"text\" name=\"$fname_value\" size=\"30\" maxlength=\"255\"></td></tr>";
}
}
So, is there a way to get the MULTIPLE fields with the same name, as $fname and $fname_value, to pass from one function to the other?? lol, sorry... it might be impossible, and I'll have to scratch all the work...
For instance, if 2 new fields are added, how do I pass them to the next function?? I need to get them passed, so the values will be added to the proper table... The function Add, will need to have the values like this:
Add($fname, $fname_value, and so on....)
Can I use something like:
while ($i < count($fname))
{
if ($fname[$i] != "")
{
insert to DB HERE:
}
$i++;
}
Or, something like this in the input fields... $fname[], and $fname_value[], and then use the foreach function or something?? lol.. the noob is coming out...
I sure hope someone can understand all this... lol... if not, I understand totally... It's quite long, and I might need to provide more info...
Or, if you can contact me with a PM and help out, I can send you some money through paypal or something... hell, I just need this thing figured out already... Been trying for 3 days... grrrrrrr.
I just don't want to start from scratch...
Thanks!
Shawn