Jump to content

Recommended Posts

Here is the code:

[code]<?php
session_start();
header("Cache-control: private");
$person_id = $_SESSION['page'];
$customer_id = $_SESSION['stamp'];
$c = $_SESSION['c'];
$m1 = $_SESSION['m1'];
$m2 = $_SESSION['m2'];
$plan_id = $_POST['Plans'];
$medical = array(array());
include 'header.html';

# Connect to MySQL
$connection = @mysql_connect("localhost", "??", "??") or die("Could not connect to MySQL.");

# Select the specified database.
$result = @mysql_select_db("sfb", $connection) or die("Could not select the requested database.");
?>

<table width=175 border=0 align="left" cellpadding=0 cellspacing=0>
<tr align="left" valign="top" nowrap>
  <td width=175 valign="top" nowrap><img src="../images/NAV-pic.jpg" border=0></td>
</tr><tr align="left" valign="top" nowrap>
  <td align="left" nowrap><a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image6','','NAV-home-on.gif',0)"><img src="../images/NAV-home.gif" alt="home" name="Image6" border=0></a></td>
</tr><tr align="left" valign="top" nowrap>
  <td align="left" nowrap><a href="products.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','NAV-products-on.gif',0)"><img src="../images/NAV-products.gif" alt="Products & Services" name="Image7" border=0></a></td>
</tr><tr align="left" valign="top" nowrap>
  <td align="left" nowrap><a href="csa.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image19','','NAV-service-on.gif',0)"><img src="../images/NAV-service-on.gif" alt="Customer Service Area" name="Image19" border=0></a></td>
</tr><tr align="left" valign="top" nowrap>
  <td align="left" nowrap><a href="quotes.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9','','NAV-quotes-on.gif',0)"><img src="../images/NAV-quotes.gif" alt="Online Quotes" name="Image9" border=0></a></td>
</tr><tr align="left" valign="top" nowrap>
  <td align="left" nowrap><a href="free.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image17','','NAV-info-on.gif',0)"><img src="../images/NAV-info.gif" alt="Free Information" name="Image17" border=0></a></td>
</tr><tr align="left" valign="top" nowrap>
  <td align="left" nowrap><a href="about.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image18','','NAV-about-on.gif',0)"><img src="../images/NAV-about.gif" alt="About Us" name="Image18" width=175 height=24 border=0></a></td>
</tr>    
</table>

<?php
$self = $_SERVER['PHP_SELF'];
echo ("<form action=\"$self\" method=\"post\">");
?>

<h2><?php echo $c;?><br>Add/Edit/Delete Major Medical Plan</h2>
    <select name="Plans" size=5>
<?php
$query = "select * from medical order by plan_name";
$result = mysql_query($query,$connection) or die ("Could not find any plans.");

while ($row = mysql_fetch_assoc($result)) {
  $id = $row['plan_id'];
  if ($id == $plan_id) {
    echo ("  <option selected value=");
  } else {
    echo ("  <option value=");
  }
  echo $id . ">" . $row['plan_name'] . " ~ " . $row['carrier'];
  if ($row['network'] == "Y") {
    echo " ~ Network</option>\n";
  } else {
    echo " ~ Non-network</option>\n";
  }

  $j = 0;
  foreach ($row as $info) {
    $medical[$id][$j] = $info;
    $j++;
  }
}
?>
</select><br>
Select a plan, then click, <input type="submit" name="View" value="View Plan Details"><br><br>
<table width=595 border=0 cellpadding=0 cellspacing=0>
<?php
if ($plan_id > 0) {
  if ($medical[$plan_id][3] == "Y") {
    echo "<tr><td>" . $medical[$plan_id][$k] . "</td></tr>";
  } else {
    for ($k=4;$k<$j;$k=$k+7) {
      echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"<?php echo isset($_POST['View'])?$row['customer_address1']:\'\';?>\"></td></tr>";
    }
  }
} else {
  for ($k=4;$k<$j;$k=$k+7) {
    echo "<tr><td>" . $medical[0][$k] . "</td></tr>";
  }
}
?>
</table>
<!--#include virtual="footer.html" --> [/code]

The problem is in the line:

[code]      echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"<?php echo isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";[/code]
The last pair of \' cause no problem, but all of the other \' cause the parser to halt (I think that's the right way to say it - nothing appears on the Web page).

I know that I can put $_POST['View'] and $row['customer_address1'] into variables outside of this echo statement and be done with the problem, but I'd like to learn how to do this correctly, rather than just make it work. What do I do to make the code work correctly?
Link to comment
https://forums.phpfreaks.com/topic/12018-how-do-i-echo-within-echo/
Share on other sites

[!--quoteo(post=383984:date=Jun 14 2006, 03:47 PM:name=FourEyes)--][div class=\'quotetop\']QUOTE(FourEyes @ Jun 14 2006, 03:47 PM) [snapback]383984[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Here is the code:

echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"<?php echo isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";

The last pair of \' cause no problem, but all of the other \' cause the parser to halt (I think that's the right way to say it - nothing appears on the Web page).

I know that I can put $_POST['View'] and $row['customer_address1'] into variables outside of this echo statement and be done with the problem, but I'd like to learn how to do this correctly, rather than just make it work. What do I do to make the
[/quote]


Why are you calling [code]<?php[/code] again? It's already open...

Have you just tried just removing the <?php, ?> & second echo?
[code]echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"<?php echo isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";[/code]

Lets break this down... I have a question. Are you trying to add something to the name? name=field$k? Also, if you want to echo something, why not just turn it into a variable?

$new_variable = "isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";

I also agree with tidalik... How come you are re-opening the <?php tag? That doesn't make sense to me.

idk, maybe I am wrong, but that is what I may do... I am new to php, trying to learn a lot, but when it comes to these things, I may be wrong. So, I hope I helped in any way?
[!--quoteo(post=383985:date=Jun 14 2006, 04:52 PM:name=tidalik)--][div class=\'quotetop\']QUOTE(tidalik @ Jun 14 2006, 04:52 PM) [snapback]383985[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Why are you calling [code]<?php[/code] again? It's already open...

Have you just tried just removing the <?php, ?> & second echo?
[/quote]


I did. No change, I still have a blank page.

[!--quoteo(post=383992:date=Jun 14 2006, 05:32 PM:name=effigy)--][div class=\'quotetop\']QUOTE(effigy @ Jun 14 2006, 05:32 PM) [snapback]383992[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Have a look at heredoc (see signature).
[/quote]

I read it. I don't see how this applies to my situation.

[!--quoteo(post=384088:date=Jun 15 2006, 02:58 AM:name=JP128)--][div class=\'quotetop\']QUOTE(JP128 @ Jun 15 2006, 02:58 AM) [snapback]384088[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"<?php echo isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";[/code]

Lets break this down... I have a question. Are you trying to add something to the name? name=field$k? Also, if you want to echo something, why not just turn it into a variable?

$new_variable = "isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";

I also agree with tidalik... How come you are re-opening the <?php tag? That doesn't make sense to me.

idk, maybe I am wrong, but that is what I may do... I am new to php, trying to learn a lot, but when it comes to these things, I may be wrong. So, I hope I helped in any way?
[/quote]


Okay, re-opening PHP was ignorant on my part. Also, to solve the problem, I did as you suggest, which is put the variables into other variables that won't require quotes. It's not elegant, but it works. I just thought there was a less brute-force way.

[code]      $aa = $_POST['View'];
      $bb = $row['customer_address1'];
      echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"isset($aa)?$bb:\'\';\"></td></tr>";[/code]


Thank you all for your suggestons.
Try changing your problem code:
[code]<?php
echo "<tr><td>" . $medical[$plan_id][$k] . "</td><td><input name=\"field" . $k . " size=45 value=\"<?php echo isset($_POST[\'View\'])?$row[\'customer_address1\']:\'\';?>\"></td></tr>";
?>[/code]
to
[code]<?php
echo '<tr><td>' . $medical[$plan_id][$k] . '</td><td><input name="field' . $k . '" size=45 value="';
echo isset($_POST['View'])?$row['customer_address1']:'';
echo '"></td></tr>';
?>[/code]

Ken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.