Solved

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

Posted on 2014-02-25
6
215 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 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