How do I update mysql database when posting form without using hidden inputs?
Posted
by
user1322707
on Stack Overflow
See other posts from Stack Overflow
or by user1322707
Published on 2012-06-01T02:06:17Z
Indexed on
2012/06/01
4:41 UTC
Read the original article
Hit count: 140
I have a "members" table in mysql which has approximately 200 field names. Each user is given up to 7 website templates with 26 different values they can insert unique data into for each template. Each time they create a template, they post the form with the 26 associated values.
These 26 field names are the same for each template, but are differentiated by an integer at the end, ie _1, _2, ... _7. In the form submitting the template, I have a variable called $pid_sum which is inserted at the end of each field name to identify which template they are creating.
For instance:
<form method='post' action='create.template.php'>
<input type='hidden' name='address_1' value='address_1'>
<input type='hidden' name='city_1' value='city_1'>
<input type='hidden' name='state_1' value='state_1'>
etc...
<input type='hidden' name='address_1' value='address_2'>
<input type='hidden' name='city_1' value='city_2'>
<input type='hidden' name='state_1' value='state_2'>
etc...
<input type='hidden' name='address_2' value='address_3'>
<input type='hidden' name='city_2' value='city_3'>
<input type='hidden' name='state_2' value='state_3'>
etc...
<input type='hidden' name='address_2' value='address_4'>
<input type='hidden' name='city_2' value='city_4'>
<input type='hidden' name='state_2' value='state_4'>
etc...
<input type='hidden' name='address_2' value='address_5'>
<input type='hidden' name='city_2' value='city_5'>
<input type='hidden' name='state_2' value='state_5'>
etc...
<input type='hidden' name='address_2' value='address_6'>
<input type='hidden' name='city_2' value='city_6'>
<input type='hidden' name='state_2' value='state_6'>
etc...
<input type='hidden' name='address_2' value='address_7'>
<input type='hidden' name='city_2' value='city_7'>
<input type='hidden' name='state_2' value='state_7'>
etc...
// Visible form user fills out in creating their template ($pid_sum converts
// into an integer 1-7, depending on what template they are filling out)
<input type='' name='address_$pid_sum'>
<input type='' name='city_$pid_sum'>
<input type='' name='state_$pid_sum'>
etc...
<input type='submit' name='save_button' id='save_button' value='Save Settings'>
<form>
Each of these need updated in a hidden input tag with each form post, or the values in the database table (which aren't submitted with the form) get deleted. So I am forced to insert approximately 175 hidden input tags with every creation of 26 new values for one of the 7 templates.
Is there a PHP function or command that would enable me to update all these values without inserting 175 hidden input tags within each form post?
Here is the create.template.php file which the form action calls:
<?php
$q=new Cdb;
$t->set_file("content", "create_template.html");
$q2=new CDB;
$query="SELECT menu_category FROM menus WHERE link='create.template.ag.php'";
$q2->query($query);
$toall=0;
if ($q2->nf()<1) { $toall=1; }
while ($q2->next_record()) {
if ($q2->f('menu_category')=="main") {
$toall=1;
}
}
if ($toall==0) {
get_logged_info();
$q2=new CDB;
$query="SELECT id FROM menus WHERE link='create_template.php'";
$q2->query($query);
$q2->next_record();
$query="SELECT membership_id FROM menu_permissions WHERE menu_item='".$q2->f("id")."'";
$q2->query($query);
while ($q2->next_record()) {
$permissions[]=$q2->f("membership_id");
}
if (count($permissions)>0) {
$error='<center><font color="red"><b>You do not have access to this area!<br><br>Upgrade your membership level!</b></font></center>';
foreach ($permissions as $value) {
if ($value==$q->f("membership_id")) {
$error='';
break;
}
}
if ($error!="") {
die("$error");
}
}
}
$member_id=$q->f("id");
$pid=$q->f("pid");
$pid_sum = $pid +1;
$first_name=$q->f("first_name");
$last_name=$q->f("last_name");
$email=$q->f("email");
echo " // THIS IS WHERE THE HTML FORM GOES ";
replace_tags_t($q->f("id"), $t);
?>
© Stack Overflow or respective owner