UPDATE a field publically

9 posts by 3 authors in: Forums > CMS Builder
Last Post: July 29, 2009   (RSS)

Re: [eduran582] UPDATE a field publically

By ross - July 24, 2009

Hi Eric

Thanks for posting!

There are going to be some options on this one for you. It will basically be a variation on the add form. This may end up being something we need to look at for you through consulting though as it will start to get fairly technical.

How comfortable are you working with PHP. If I explained the general idea, would you be able to run with that?

Let me know :)
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] UPDATE a field publically

By eduran582 - July 24, 2009 - edited: July 27, 2009

Hi Ross,

Thanks for answering! I'm not too bad with PHP (I'm basically a Delphi programmer) and even though I'm not above hiring for consulting, it might give some insight to others with a similar problem. I'm game!

Eric


*** UPDATE ***

Hi Ross,

I've figured out how to POST the updated fields to the proper table and record. However, I'm running into a problem with the variables that are not contained in the table. In particular, a variable I'm trying to 'enumerate' from a drop-down field. I have a 'foreach' running that displays certain records. In each listed record, an additional form field is displayed. When an 'option' is chosen in that field, the user then clicks on the 'submit' button to initiate the POST to the other php page. This is what I have (with some code eliminated for clearity):

<table>
<?php foreach ($citationsRecords as $record): ?>
<?php $nbr++; ?>
<tr>
<td><?php echo $record['title'] ?></td>
...
...
<td><select name="finding">
<option value='- Select -'>- Select -</option>
<option value='Founded'>Founded</option>
<option value='Unfounded'>Unfounded</option>
<option value='Continued'>Continued</option>
</select></td>
</tr></table><br/>

<input type="hidden" name="<?php echo "cite$nbr" ?>" value="<?php echo $record['title'] ?>">
<input type="hidden" name="<?php echo "find$nbr" ?>" value="finding">

<?php endforeach; ?>


When the records are submitted, there's no problem showing each of the "cite$nbr" values but I can't figure out how to format the "finding" field so each value will be saved as "find$nbr". I've looked high and low for a solution but have not been able to find one.

Any help or direction would be appreciated.

Thanks!

Eric

Re: [eduran582] UPDATE a field publically

By Dave - July 27, 2009

Hi Eric,

I'm not sure I follow. So this is to update an existing record in the database, right?

What are all the fields in the form, and what fields in the database do you want to update with them?

You can use this handy debug code to show what a form is submitting:

<xmp><?php print_r($_REQUEST); ?></xmp>
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] UPDATE a field publically

By eduran582 - July 27, 2009

Hi Dave,

Thanks for replying! Your right; to update a field in an existing table; actually the same field in several records contained within the table. The only field I want to update, at this time, is the selection made from the drop-down field ("finding"). There is an associated field in the table for this record ("hearing_finding") and I was going to update with whatever is entered in the drop-down for each record. I'm using the "title" field as the index to find each record when updating in the "POST" page:

(loop starts)

$cite=$_POST["cite$nnbr"];
$result=$_POST["find$nnbr"];

mysql_query("UPDATE cms_citations SET hearing_finding = '$result' WHERE title = '$cite'");

(loop ends)

Do you need to see the page with all the code?

Eric

Re: [eduran582] UPDATE a field publically

By Dave - July 27, 2009

Ok, and you need to run that code for however many fields groups are submitted? What if we put a loop around it that checks if the input field exists?

<?php
foreach (range(1,100) as $nnbr) {
if (!array_key_exists("cite$nnbr")) { continue; }

$cite = mysql_real_escape_string( $_POST["cite$nnbr"] );
$result = mysql_real_escape_string( $_POST["find$nnbr"] );
$query = "UPDATE cms_citations SET hearing_finding = '$result' WHERE title = '$cite'";
print "$query<br/>\n"; // debug, just print queries for now


//mysql_query($query);
}


Does that help?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] UPDATE a field publically

By eduran582 - July 27, 2009

Thanks again for the quick reply!

That's great code for the update page. However, my problem is getting the variable from the drop-down from the page where the information is submitted FOR the page that handles the updates.

I have no problem with receiving the $_POST["cite$nnbr"] variable(s) (cite1 variable="AC1234567", cite2 variable="AC9876543", etc) but nothing comes through for the $_POST["find$nnbr"] variable except whatever is listed in the form field name="finding" (find1 variable ="finding", find2 variable = "finding"). Consequently, the only thing updated in the table/field is the cite variable.

Thanks again for the [better] sql code and, before I forget, thanks again for the GREAT price on CMSB you ran the last couple of days! I picked up two more license for future cite use!

Eric

Re: [eduran582] UPDATE a field publically

By Dave - July 28, 2009

Hi Eric,

Oh I get it. Ok, so you need either a unique name for each finding field, or if you want to submit multiple field values with the same form field name you need to add [] to the end. Like this: <select name="finding[]">. That will set $_POST['finding'] to be an array of values.

I don't know exactly how your form is intended to work but if you can do it with <select name="finding$nbr"> it will be simpler as all the fields may have the same number, where as with an array you'll need to loop through.

To see what's getting submitted use this debug code:
<xmp><?php print_r($_POST); ?></xmp>

Hope that helps! If there are still issues and you are able to attach the form page to this thread or post an example url that would help.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] UPDATE a field publically

By eduran582 - July 29, 2009

Thanks again, Dave, for the fine support! Your examples and explaination helped me in figuring out what I needed to do!

Eric