Solved

Why does this not work and what do I need to do differently?

Posted on 2014-02-25
6
214 Views
Last Modified: 2014-02-26
Here's my form:

 <tr>
                    <td width='25' align='center' $rclass><input type='Checkbox' name='assignCapX".$i."' value='".$capxlist[$i]["capxid"]. "'></td>
                    <td width='".($leftcol-25-100)."' $rclass><a class='tip_trigger' href=''><span class='text'>".$capxlist[$i]["description"].' '.$capxlist[$i]['capxid']."</span><span class='tip'>
                     <table width='200'><tr><td class='text'>".$capxlist[$i]["shortname"]."</td></tr></table></span></a></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                   <input type='hidden' name='shortname' value='".$capxlist[$i]["shortname"]."'>
                    <input type='hidden' name='description' value='".$capxlist[$i]["description"]."'>
                    <input type='hidden' name='totalcost' value='".$capxlist[$i]["totalcost"]."'>
                    <input type='hidden' name='assettypeid' value='".$capxlist[$i]["assettypeid"]."'>
                    <input type='hidden' name='spmodelid' value='".$capxlist[$i]["spmodelid"]."'>
                    <input type='hidden' name='capxid' value='".$capxlist[$i]["capxid"]."'></td>
                </tr>";

Open in new window


The checkbox is "checked" on the other end with this:

for ($i=1; $i<=$capx_assign; $i++) {
    eval("if (isset(\$assignCapX".$i."))
            \$tmp_set = yes;   
        else
            \$tmp_set = no;");
            echo $tmp_set;
           if ($tmp_set == "yes")
            {
            //$capx_temp_assign = cer_capxtempsave($ID, $mID, $capxid, $spmodelid, $assettypeid, $totalcost, cleanstring($description), cleanstring($shortname));
            }
    }   

Open in new window


When I view the way the code is being "seen" by the system, I'll get something like nononoyesnonoyes, but the same variables are being inserted every time. In other words, the same capxid, the same spmodelid. So while the $tmp_set value is being viewed correctly, the only variables that are being inserted are the ones belonging to the last record in the list.

What do I need to do differently to ensure that the right variables are being inserted, rather than the same ones? What am I missing?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Assisted Solution

by:Dan Craciun
Dan Craciun earned 250 total points
ID: 39886289
Sorry, but I think some code is missing.
On the first snippet you don't have the loop where $i is incremented.
Can you post the full form with the loop?

Dan
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 125 total points
ID: 39886396
Why are you using eval?

for ($i=1; $i<=$capx_assign; $i++) {
	if (isset(${'assignCapX'.$i}))
            $tmp_set = 'yes';
        else
            $tmp_set = 'no';
	echo $tmp_set;
	if ($tmp_set == 'yes'){
		//$capx_temp_assign = cer_capxtempsave($ID, $mID, $capxid, $spmodelid, $assettypeid, $totalcost, cleanstring($description), cleanstring($shortname));
	}
}

Open in new window

0
 

Author Comment

by:brucegust
ID: 39886436
Here's the full form:

    for ($i=1;$i<=$capxlist["count"];$i++) {
                $rc_count++;
                $hlf = floor($rc_count/2);
                $dbl = $hlf*2;
                
                if ($rc_count != $dbl)
                    $rclass = " class=''";
                else
                    $rclass = " class='rcolor'";
                    if($capxcompare["count"]>0)
                    {
        continue;
                    }
                    else
                    {
                echo "
                <tr>
                    <td width='25' align='center' $rclass><input type='Checkbox' name='assignCapX".$i."' value='".$capxlist[$i]["capxid"]. "'></td>
                    <td width='".($leftcol-25-100)."' $rclass><a class='tip_trigger' href=''><span class='text'>".$capxlist[$i]["description"].' '.$capxlist[$i]['capxid']."</span><span class='tip'>
                     <table width='200'><tr><td class='text'>".$capxlist[$i]["shortname"]."</td></tr></table></span></a></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                    <td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
                   <input type='hidden' name='shortname' value='".$capxlist[$i]["shortname"]."'>
                    <input type='hidden' name='description' value='".$capxlist[$i]["description"]."'>
                    <input type='hidden' name='totalcost' value='".$capxlist[$i]["totalcost"]."'>
                    <input type='hidden' name='assettypeid' value='".$capxlist[$i]["assettypeid"]."'>
                    <input type='hidden' name='spmodelid' value='".$capxlist[$i]["spmodelid"]."'>
                    <input type='hidden' name='capxid' value='".$capxlist[$i]["capxid"]."'></td>
                </tr>";
                    }
                }

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
Dan Craciun earned 250 total points
ID: 39886531
I don't understand your need of "continue". This is how the loop should look, in my opinion:
<?php
for ($i=1;$i<=$capxlist["count"];$i++) {
	$rc_count++;
	$hlf = floor($rc_count/2);
	$dbl = $hlf*2;
	
	if ($rc_count != $dbl)
		$rclass = " class=''";
	else
		$rclass = " class='rcolor'";
	if($capxcompare["count"]<=0)
		{
		echo "
		<tr>
			<td width='25' align='center' $rclass><input type='Checkbox' name='assignCapX".$i."' value='".$capxlist[$i]["capxid"]. "'></td>
			<td width='".($leftcol-25-100)."' $rclass><a class='tip_trigger' href=''><span class='text'>".$capxlist[$i]["description"].' '.$capxlist[$i]['capxid']."</span><span class='tip'>
			 <table width='200'><tr><td class='text'>".$capxlist[$i]["shortname"]."</td></tr></table></span></a></td>
			<td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
			<td width='75' $rclass><span class='info'>$".number_format($capxlist[$i]["totalcost"],2)."</span></td>
		   <input type='hidden' name='shortname' value='".$capxlist[$i]["shortname"]."'>
			<input type='hidden' name='description' value='".$capxlist[$i]["description"]."'>
			<input type='hidden' name='totalcost' value='".$capxlist[$i]["totalcost"]."'>
			<input type='hidden' name='assettypeid' value='".$capxlist[$i]["assettypeid"]."'>
			<input type='hidden' name='spmodelid' value='".$capxlist[$i]["spmodelid"]."'>
			<input type='hidden' name='capxid' value='".$capxlist[$i]["capxid"]."'></td>
		</tr>";
		}
	}
?>

Open in new window

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
ID: 39886604
You can probably make things a lot easier if you learn about HEREDOC syntax.  There will be a lot less fiddly punctuation.  Heed, but do not be put off by, the warning.
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

As far as eval() goes, it's like goto.  Just don't.  The Apple security bug was caused by a goto statement.  And it's not like we haven't been warned.
http://xkcd.com/292/

To the meat of this question... it appears to be data-dependent.  If you can show us the data and tell us what you want to achieve we can almost certainly give you a tested and working code example.
0
 

Author Comment

by:brucegust
ID: 39889463
I figured it out.

I had some notes from a previous meeting with my team leader and he referenced the importance of "$i" which I didn't really understand until after the fact.

Bottom line: The information is coming as an array so I established some temporary variables and then submitted them to my insert statement based on whether or not the original check box had been selected. So it looks like this:

     eval("\$tmp_capxid = \$capxid".$i.";");
                eval("\$tmp_spmodelid = \$spmodelid".$i.";");
                eval("\$tmp_assettypeid = \$assettypeid".$i.";");
                eval("\$tmp_totalcost = \$totalcost".$i.";");
                eval("\$tmp_description = \$description".$i.";");
                eval("\$tmp_shortname = \$shortname".$i.";");
                eval("\$tmp_allocatedamount = \$allocatedamount".$i.";");
                             
                $capx_temp_assign = cer_capxtempsave($ID, $mID, $tmp_capxid, $tmp_spmodelid, $tmp_assettypeid, $tmp_totalcost, cleanstring($tmp_description), cleanstring($tmp_shortname), $tmp_allocatedamount);

Now, I get the variables I'm needing and all is gold.

Thanks everybody for weighing in!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question