[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    Re: [PHP] Re: Dynamically Created Checkboxes
From:       68.80.24.111
Date:       2011-02-24 18:14:09
Message-ID: 8B.60.14561.9FF966D4 () pb1 ! pair ! com
[Download RAW message or body]


"Steve Staples" <sstaples@mnsi.net> wrote in message 
news:1298570683.14826.2438.camel@webdev01...
> On Thu, 2011-02-24 at 12:52 -0500, Gary wrote:
> > "Steve Staples" <sstaples@mnsi.net> wrote in message
> > news:1298568238.14826.2431.camel@webdev01...
> > > On Thu, 2011-02-24 at 11:42 -0500, Gary wrote:
> > > > "Steve Staples" <sstaples@mnsi.net> wrote in message
> > > > news:1298492194.14826.2425.camel@webdev01...
> > > > > On Wed, 2011-02-23 at 14:56 -0500, Gary wrote:
> > > > > > "Steve Staples" <sstaples@mnsi.net> wrote in message
> > > > > > news:1298490417.14826.2418.camel@webdev01...
> > > > > > > On Wed, 2011-02-23 at 14:17 -0500, Gary wrote:
> > > > > > > > "Jim Lucas" <lists@cmsws.com> wrote in message
> > > > > > > > news:4D653673.7040604@cmsws.com...
> > > > > > > > > On 2/23/2011 4:35 AM, Gary wrote:
> > > > > > > > > > "Pete Ford" <pete@justcroft.com> wrote in message
> > > > > > > > > > news:62.C1.32612.D49D46D4@pb1.pair.com...
> > > > > > > > > > > This bit?
> > > > > > > > > > > 
> > > > > > > > > > > On 22/02/11 22:06, Gary wrote:
> > > > > > > > > > > > for($i=1; $i<=$_POST['counties']; $i++) {
> > > > > > > > > > > > if ( isset($_POST["county{$i}"] ) ) {
> > > > > > > > > > > 
> > > > > > > > > > > You loop over $_POST['counties'] and look for
> > > > > > > > > > > $_POST["county$i"]
> > > > > > > > > > > 
> > > > > > > > > > > I suspect that there is no field 'counties' in your form, so
> > > > > > > > > > > the
> > > > > > > > > > > server
> > > > > > > > > > > is
> > > > > > > > > > > complaining about the missing index - seems likely that the
> > > > > > > > > > > production
> > > > > > > > > > > server
> > > > > > > > > > > is not showing the error, but instead just giving up on the
> > > > > > > > > > > page.
> > > > > > > > > > > 
> > > > > > > > > > > I think the IE7/Firefox browser difference is a red herring: 
> > > > > > > > > > > it
> > > > > > > > > > > wasn't
> > > > > > > > > > > actually working in any browser, or the code changed between
> > > > > > > > > > > tests.
> > > > > > > > > > > Remember, PHP is server side and generates HTML (or 
> > > > > > > > > > > whatever).
> > > > > > > > > > > Unless
> > > > > > > > > > > you
> > > > > > > > > > > tell the PHP what browser you are using and write PHP code 
> > > > > > > > > > > to
> > > > > > > > > > > take
> > > > > > > > > > > account
> > > > > > > > > > > of that (not generally recommended) then the server output 
> > > > > > > > > > > is
> > > > > > > > > > > the
> > > > > > > > > > > same
> > > > > > > > > > > regardless of browser.
> > > > > > > > > > > 
> > > > > > > > > > > -- 
> > > > > > > > > > > Peter Ford, Developer                 phone: 01580 893333 
> > > > > > > > > > > fax:
> > > > > > > > > > > 01580
> > > > > > > > > > > 893399
> > > > > > > > > > > Justcroft International Ltd.
> > > > > > > > > > > www.justcroft.com
> > > > > > > > > > > Justcroft House, High Street, Staplehurst, Kent   TN12 0AH
> > > > > > > > > > > United
> > > > > > > > > > > Kingdom
> > > > > > > > > > > Registered in England and Wales: 2297906
> > > > > > > > > > > Registered office: Stag Gates House, 63/64 The Avenue,
> > > > > > > > > > > Southampton
> > > > > > > > > > > SO17
> > > > > > > > > > > 1XS
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > Pete
> > > > > > > > > > 
> > > > > > > > > > Once again, thank you for your help.
> > > > > > > > > > 
> > > > > > > > > > I was able to get it to work, I did not understand the 
> > > > > > > > > > browser
> > > > > > > > > > differences
> > > > > > > > > > either, but on my testing server on IE, it worked as I wanted
> > > > > > > > > > but
> > > > > > > > > > not
> > > > > > > > > > on
> > > > > > > > > > anything else.  I chopped out most of the code and ended up 
> > > > > > > > > > with
> > > > > > > > > > this:
> > > > > > > > > > 
> > > > > > > > > > if ( isset($_POST['submit']) ) {} else {
> > > > > > > > > > print "<form action=\"phpForm3.php\" method=\"POST\">\n";
> > > > > > > > > > if ($Recordset1) {
> > > > > > > > > > print "<table width=200 border=1>\n";
> > > > > > > > > > print "<th>&nbsp; </th>\n";
> > > > > > > > > > print "<th> State </th>\n"; //2 fields in Counties table, 
> > > > > > > > > > State
> > > > > > > > > > and
> > > > > > > > > > County
> > > > > > > > > > print "<th> County </th>\n";
> > > > > > > > > > print "</tr>\n";
> > > > > > > > > > //create table
> > > > > > > > > > $i = 0;
> > > > > > > > > > while ( $row = mysql_fetch_array($Recordset1) ) {
> > > > > > > > > > $i++;
> > > > > > > > > > print "<tr>\n";
> > > > > > > > > > print "<td><input type=\"checkbox\" name=\"county$i\"
> > > > > > > > > > value=\"$row[name]\"></td>\n";
> > > > > > > > > > echo "<td>{$row['state_id']}</td>\n";
> > > > > > > > > > echo "<td>{$row['name']}</td>\n";
> > > > > > > > > > echo "</tr>\n";
> > > > > > > > > > }//end while
> > > > > > > > > > print "</table>\n";
> > > > > > > > > > } else {
> > > > > > > > > > echo("<P>Error performing query: " .
> > > > > > > > > > mysql_error() . "</P>");
> > > > > > > > > > }
> > > > > > > > > > print "<input type=\"hidden\" name=\"counties\"
> > > > > > > > > > value=\"$i\"/>\n";
> > > > > > > > > > print "<input type=\"submit\" name=\"submit\" 
> > > > > > > > > > value=\"Go\"/>\n";
> > > > > > > > > > }
> > > > > > > > > > ?>
> > > > > > > > > > 
> > > > > > > > > > Again, thank you.
> > > > > > > > > > 
> > > > > > > > > > Gary
> > > > > > > > > > 
> > > > > > > > > > __________ Information from ESET Smart Security, version of
> > > > > > > > > > virus
> > > > > > > > > > signature database 5899 (20110223) __________
> > > > > > > > > > 
> > > > > > > > > > The message was checked by ESET Smart Security.
> > > > > > > > > > 
> > > > > > > > > > http://www.eset.com
> > > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > If you would allow me to show you a little easier way of doing
> > > > > > > > > this.
> > > > > > > > > 
> > > > > > > > > if ( !isset($_POST['submit']) ) {
> > > > > > > > > echo '<form action="phpForm3.php" method="POST">';
> > > > > > > > > if ($Recordset1) {
> > > > > > > > > echo <<<HEADER
> > > > > > > > > <table width=200 border=1>
> > > > > > > > > <tr><th> &nbsp; </th><th> State </th><th> County </th></tr>
> > > > > > > > > HEADER;
> > > > > > > > > while ( $row = mysql_fetch_array($Recordset1) ) {
> > > > > > > > > echo <<<ROW
> > > > > > > > > <tr>
> > > > > > > > > <td><input type="checkbox" name="county[]"
> > > > > > > > > value="{$row['name']}"></td>
> > > > > > > > > <td>{$row['state_id']}</td>
> > > > > > > > > <td>{$row['name']}</td>
> > > > > > > > > </tr>
> > > > > > > > > ROW;
> > > > > > > > > }//end while
> > > > > > > > > echo '</table>';
> > > > > > > > > } else {
> > > > > > > > > echo '<p>Error performing query: '.mysql_error().'</p>';
> > > > > > > > > }
> > > > > > > > > echo '<input type="submit" name="submit" value="Go" />';
> > > > > > > > > }
> > > > > > > > > 
> > > > > > > > > Now, the main thing I want you to see is the line for the 
> > > > > > > > > country
> > > > > > > > > checkbox'es
> > > > > > > > > 
> > > > > > > > > The county[] turns the submitted values into an array.  So, in
> > > > > > > > > the
> > > > > > > > > processing
> > > > > > > > > script, you would do this.
> > > > > > > > > 
> > > > > > > > > <?php
> > > > > > > > > 
> > > > > > > > > ...
> > > > > > > > > 
> > > > > > > > > if ( !empty($_POST['county'])
> > > > > > > > > foreach ( $_POST['county'] AS $id => $name )
> > > > > > > > > echo "{$id} {$name}\n";
> > > > > > > > > 
> > > > > > > > > ...
> > > > > > > > > ?>
> > > > > > > > > 
> > > > > > > > > Hope this clears things up for you a little.
> > > > > > > > > 
> > > > > > > > > Enjoy.
> > > > > > > > > 
> > > > > > > > > Jim
> > > > > > > > 
> > > > > > > > In a weird twist, I have/had  the script working, but again it 
> > > > > > > > is
> > > > > > > > not
> > > > > > > > working in FF or Chrome.  This is a link to the first page which
> > > > > > > > runs
> > > > > > > > you
> > > > > > > > through the pages.
> > > > > > > > 
> > > > > > > > I have the submit to trigger upon change so there is no submit
> > > > > > > > button.
> > > > > > > > This
> > > > > > > > works in IE7.  If I add a submit button, it does not work in any 
> > > > > > > > of
> > > > > > > > them.
> > > > > > > > 
> > > > > > > > I am wondering if this is more a problem with the html.
> > > > > > > > 
> > > > > > > > 
> > > > > > > > http://www.assessmentappeallawyer.com/forum_state.php
> > > > > > > > 
> > > > > > > > This is the code for the first processing page
> > > > > > > > 
> > > > > > > > if ( !isset($_POST['submit']) ) {
> > > > > > > > echo '<form action="forum_delete.php" method="POST">';
> > > > > > > > if ($Recordset1) {
> > > > > > > > echo <<<HEADER
> > > > > > > > <table width=200 border=0>
> > > > > > > > <tr><th> &nbsp; </th><th> State </th><th> County </th></tr>
> > > > > > > > HEADER;
> > > > > > > > while ( $row = mysql_fetch_array($Recordset1) ) {
> > > > > > > > echo <<<ROW
> > > > > > > > <tr>
> > > > > > > > <td><input type="checkbox" name="county[]"
> > > > > > > > value="{$row['name']}"></td>
> > > > > > > > <td>{$row['state_id']}</td>
> > > > > > > > <td>{$row['name']}</td>
> > > > > > > > </tr>
> > > > > > > > ROW;
> > > > > > > > }//end while
> > > > > > > > echo '</table>';
> > > > > > > > } else {
> > > > > > > > echo '<p>Error performing query: '.mysql_error().'</p>';
> > > > > > > > }
> > > > > > > > echo '<input type="submit" name="submit" value="Select" />';
> > > > > > > > }
> > > > > > > > 
> > > > > > > > ?>
> > > > > > > > 
> > > > > > > > ****This is the code for the second processing page.
> > > > > > > > 
> > > > > > > > 
> > > > > > > > <?php
> > > > > > > > 
> > > > > > > > 
> > > > > > > > if ( !empty($_POST['county']))
> > > > > > > > foreach ( $_POST['county'] AS $id => $name )
> > > > > > > > echo 'You have selected '. " {$name}".'<br />';
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > $totalRows_county_result_net= "($totalRows_county_result) + 
> > > > > > > > (1)";
> > > > > > > > echo "[$totalRows_county_result_net]";
> > > > > > > > echo "$totalRows_county_result";
> > > > > > > > ?>
> > > > > > > > </div>
> > > > > > > > <!--eo center-->
> > > > > > > > 
> > > > > > > > 
> > > > > > > > <?php
> > > > > > > > $name=$_POST['name'];
> > > > > > > > echo 'You have selected'."$name";
> > > > > > > > 
> > > > > > > > ?>
> > > > > > > > <?php
> > > > > > > > mysql_free_result($county_result);
> > > > > > > > ?>
> > > > > > > > 
> > > > > > > > Again, thank you for any input.
> > > > > > > > 
> > > > > > > > Gary
> > > > > > > 
> > > > > > > I think it may have to do with HTML, or the fact that IE is
> > > > > > > "helping"
> > > > > > > you with your coding... where FF and Chrome are usually more
> > > > > > > "literal" (yet better IMO). Also, the fact that "submit" has not
> > > > > > > been
> > > > > > > defined.
> > > > > > > 
> > > > > > > try adding:
> > > > > > > <input type="submit" name="submit" value="submit" style="display:
> > > > > > > none;" />
> > > > > > > 
> > > > > > > This *SHOULD* give you the submit button, but the style is 
> > > > > > > "hidden"
> > > > > > > now,
> > > > > > > so it shouldn't show, but it will fire off the "submit" action...
> > > > > > > make
> > > > > > > sure it is in between the <form></form> tags though.
> > > > > > > 
> > > > > > > Steve
> > > > > > > 
> > > > > > Steve
> > > > > > 
> > > > > > Thank you for your reply, I had inserted a submit button prior, but 
> > > > > > it
> > > > > > did
> > > > > > not work.  I tried your suggestions and got the same result.  I am 
> > > > > > not
> > > > > > seeing anything in the html that should be causing the hick-up, but
> > > > > > given
> > > > > > the php is run on the server as Peter pointed out, browser issues 
> > > > > > with
> > > > > > php I
> > > > > > have not really encountered before.
> > > > > > 
> > > > > > I can live with a submit button, but living with one that does not
> > > > > > work...
> > > > > > 
> > > > > > Thank you for your input, if you see anything else that seems 
> > > > > > amiss,
> > > > > > please
> > > > > > let me know.
> > > > > > 
> > > > > > Gary
> > > > > > 
> > > > > 
> > > > > the <form onchange="submit"> as far as I know, isn't a 
> > > > > standard/valid
> > > > > html attribute...  so I would remove it altogether.
> > > > > http://www.w3schools.com/tags/tag_form.asp
> > > > > 
> > > > > 
> > > > > and try on the <select ... onchange=""> to be
> > > > > <select .... onchange="document.forms["Form1"].submit();">
> > > > > where Form1 is the id of the form (so add that to the <form...>
> > > > > <form id="Form1" ... >
> > > > > 
> > > > > try that... (i haven't been testing... my fault... but I am in the
> > > > > midst
> > > > > of work right now to really test it out)
> > > > > 
> > > > > good luck!
> > > > > 
> > > > > Steve
> > > > 
> > > > Thank you to everybody that has helped.  As it is now, I have the
> > > > checkboxes
> > > > appearing in all browers, but I am unable to pass the "checked" values 
> > > > to
> > > > the next page which echo's the choices.
> > > > 
> > > > The page that produces the checkboxes is here: (and this works fine)
> > > > 
> > > > 
> > > > 
> > > > if ( isset($_POST['submit']) ) { // if form is submitted, process it
> > > > 
> > > > 
> > > > print "<form action=\"phpForm3.php\" method=\"POST\">\n";
> > > > 
> > > > 
> > > > 
> > > > if ($Recordset1) {
> > > > print "<table width=200 border=0>\n";
> > > > 
> > > > print "<th>&nbsp; </th>\n";
> > > > 
> > > > 
> > > > print "</tr>\n";
> > > > //create table
> > > > $i = 0;
> > > > while ( $row = mysql_fetch_array($Recordset1) ) {
> > > > $i++;
> > > > print "<tr>\n";
> > > > 
> > > > print "<td><input type=\"checkbox\" name=\"county$i\"
> > > > value=\"$row[name]\"></td>\n";
> > > > 
> > > > /*echo "<td>{$row['state_id']}</td>\n";*/
> > > > 
> > > > echo "<td>{$row['name']}</td>\n";
> > > > 
> > > > echo "</tr>\n";
> > > > 
> > > > }//end while
> > > > print "</table>\n";
> > > > } else {
> > > > echo("<P>Error performing query: " .
> > > > mysql_error() . "</P>");
> > > > 
> > > > }
> > > > print "<input type=\"hidden\" name=\"counties\" value=\"$i\"/>\n";
> > > > print "<input type=\"submit\" name=\"submit\" value=\"Go\"/>\n";
> > > > }?>
> > > > 
> > > > ***************
> > > > 
> > > > My query on phpForm3.php is
> > > > 
> > > > $query_county_result = "SELECT * FROM counties WHERE name = 'checked' 
> > > > ";
> > > > 
> > > > Which is to be displayed by
> > > > 
> > > > if ( !empty($_POST['county']))
> > > > foreach ( $_POST['county'] AS $id => $name )
> > > > echo 'You have selected '. " {$name}".'<br />';
> > > > 
> > > > I get a blank page and mysql_num_row returns 0
> > > > 
> > > > Again, sorry I am not getting this and thank you for all your help.
> > > > 
> > > > Gary
> > > > 
> > > > 
> > > 
> > > to get back to your other issue you were having, i've created a test
> > > page from your code:
> > > http://pastebin.com/WCH6HQ4Q
> > > 
> > > basically, remove the submit, change the onchange event for the select,
> > > and then add the javascript function.   this should work in all 
> > > browsers
> > > (unless of course you have javascript disabled (which was talked about 
> > > a
> > > few weeks/months ago)
> > > 
> > > NOW, for this issue you have today... checkboxes are an array... so you
> > > will need to use it as:
> > > <input type="checkbox" name="wahtever[]" value="something"> some text
> > > 
> > > notice the [] in the name attribute of the checkbox?
> > > 
> > > Hope that all works... (this is also not a PHP related question...
> > > hasn't really been all along, more like HTML and Javascript, but I am
> > > glad to help if i can)
> > > 
> > > Steve
> > 
> > 
> > Steve
> > 
> > As always thank you.
> > 
> > I'm not sure we are on the same page (unless I don't understand your 
> > answer
> > which of course is entirly possible).  I have the checkboxes displayed 
> > using
> > this
> > 
> > print "<td><input type=\"checkbox\" name=\"county$i\"
> > value=\"$row[name]\"></td>\n";
> > 
> > I ended up using a submit button which seems to work fine.
> > 
> > I had the results of those checkboxes being displayed on the next page, 
> > but
> > now it does not.
> > 
> > The query is
> > 
> > mysql_select_db($database_assess, $assess_remote);
> > $query_county_result = "SELECT * FROM counties WHERE name ='checked'";
> > $county_result = mysql_query($query_county_result, $assess_remote) or
> > die(mysql_error());
> > $row_county_result = mysql_fetch_assoc($county_result);
> > $totalRows_county_result = mysql_num_rows($county_result);
> > 
> > The script to display it is
> > 
> > if ( !empty($_POST['county']))
> > foreach ( $_POST['county'] AS $id => $name )
> > echo 'You have selected '. " {$name}".'<br />';
> > 
> > Frustrating how it was working, now it is not.
> > 
> > Thanks again.
> > 
> > Gary
> > 
> 
> Gary,
> 
> <input type=\"checkbox\" name=\"county$i\" value=\"$row[name]\">
> 
> the problem is, is that "county" is not an array... it would be:
> county01
> county02
> county03... and so on
> 
> so when you do:
> 
> if ( !empty($_POST['county']))
> foreach ( $_POST['county'] AS $id => $name )
> echo 'You have selected '. " {$name}".'<br />'
> 
> there is no $_POST['county'] as they would all be $_POST['county01'] and 
> so forth
> 
> NOW... if you change the checkboxes to:
> <input type=\"checkbox\" name=\"county[$i]\" value=\"$row[name]\">
> 
> you will have the array of checkboxes called $_POST['county']
> 
> 
> to test simply what the post is, on the page that you're submitting to,
> echo "<pre>";
> print_r($_POST);
> echo "</pre>";
> exit;
> 
> and it will show you all your $_POST variables that you're sending.
> 
> 
> Good luck, and BOY has this "thread" has gotten huge... since this is
> really an HTML issue (the syntax seems to be HTML, and the PHP coding
> seems to correct)  you can email me off list to continue this if you'd
> like, as to not CLOG the list with the HTML issue... (just trying to be
> considerate)
> 
> Steve


Yes, thank you very much, that seems to have solved it all.

Thank you

Gary 



__________ Information from ESET Smart Security, version of virus signature database \
5904 (20110224) __________

The message was checked by ESET Smart Security.

http://www.eset.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic