Solved

PHP Output

Posted on 2012-04-02
17
198 Views
Last Modified: 2012-04-03
I have a line of PHP code:

echo "<A HREF='ems_registration.php?regid='" .$row['RegID'] ."/>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Open in new window


but the .$row['RegID'] isn't showing up in the outputted HTML.   If I put it anywhere else, it shows up so I know the variable is correct.   What is wrong with my syntax??
0
Comment
Question by:digitalwise
  • 5
  • 4
  • 4
  • +1
17 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37796703
Try this: var_dump($row); and post the output here, thanks.
0
 

Author Comment

by:digitalwise
ID: 37796720
array(56) { [0]=> string(1) "5" ["RegID"]=> string(1) "5" [1]=> string(7) "Heather" ["FirstName"]=> string(7) "Heather" [2]=> string(5) "Lukes" ["LastName"]=> string(5) "Lukes" }
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37796732
Visit this page and use view source.  It looks like quote marks are misplaced in the echo statement.  I will try to show you a better way to do this.
http://www.laprbass.com/RAY_temp_digitalwise.php
<?php // RAY_temp_digitalwise.php
error_reporting(E_ALL);


// SET THE VARIABLES
$row['RegID']     = 'Foo';
$row['FirstName'] = 'Ray';
$row['LastName']  = 'Paseur';

// USE THE VARIABLES IN AN ECHO STATEMENT COPIED FROM EE
echo "<A HREF='ems_registration.php?regid='" .$row['RegID'] ."/>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Open in new window

Back in a moment with an alternate suggestion...
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796734
You have a unneeded slash

echo "<A HREF='ems_registration.php?regid='" .$row['RegID'] ."/>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Just delete it and see what happens (it's also preferable to use lowercase for html:

echo "<a href='ems_registration.php?regid='" .$row['RegID'] .">" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

Cheers
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 37796741
I don't see a problem with what you've shown so far, so the problem is likely outside this piece of code somewhere. Can you show us a little more of the surrounding code (including the place where you ran the var_dump($row))?
0
 

Author Comment

by:digitalwise
ID: 37796754
Had a little bit of garbage everywhere!   Thanks for the Monday morning extra set of eyes.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37796762
Try it more like this...
<?php // RAY_temp_digitalwise.php
error_reporting(E_ALL);

// SET THE VARIABLES
$row['RegID']     = 'Foo';
$row['FirstName'] = 'Ray';
$row['LastName']  = 'Paseur';

// CREATE A LINK
$lnk
= '<a href="ems_registration.php?regid='
. $row['RegID']
. '">'
. $row['FirstName']
. ' '
. $row['LastName']
. '</a>'
. PHP_EOL
;

echo $lnk;

Open in new window

I find that if I put only one thing on each line, I write code that is easier to read and debug.  One other note - if you use mysql_fetch_assoc() to retrieve the rows from the query results set, you will not get the numerically indexed array positions and it will make your results set 1/2 the size that it is now.  Might improve performance ;-)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796777
Another thing: you should move quote from

echo "<a href='ems_registration.php?regid='" .$row['RegID'] .">" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

to

echo "<a href='ems_registration.php?regid=" .$row['RegID'] ."'>" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

Cheers and thanks for points
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Expert Comment

by:gr8gonzo
ID: 37796783
What was the final problem? While that slash wasn't correct HTML, it shouldn't have prevented the number from showing up in the source code...?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796788
It'sa not so evident with bold: I used here parenthesis and spaces:

From:

echo "<a href='ems_registration.php?regid= (') " .$row['RegID'] .">" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

To:

echo "<a href='ems_registration.php?regid=" .$row['RegID'] ." (') >" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

Cheers
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37796790
The accepted solution generates an invalid HTML string
<a href='ems_registration.php?regid='Foo>Ray Paseur</a>

Open in new window

I have asked a moderator to reopen the question so a correct solution can be accepted.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796819
@gr8gonzo You're right. Effectively I don't know why my answer has been accepted. Ray has shown the value were shown in the source code. But viewing the ray's sample I saw the quote problem: this problem prevents the link to work. So my think is that our asker has not checked visually the source code but he tried the link and seeing it didn't work has desumed the variable were not shown. But this is only my ideas
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 37796820
@marqusG - I understand there were changes to the HTML output, but it sounded like the RegID wasn't showing up. It's possible it was showing up in the source, but the author was judging its existence by whether or not it was there after the link was clicked.
0
 

Author Comment

by:digitalwise
ID: 37796826
OK - the good code was:
echo "<A HREF='ems_registration.php?regid=" .$row['RegID'] ."'>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796830
@Ray: you're right also. In fact I have added a comment to fix the quote problem. But the invalid HTML were in the question yet... :-)
0
 

Author Comment

by:digitalwise
ID: 37796843
Guys - Ray provided me with the path to fix the issue.   When I accepted the solution, I didn't see that others had been offering solutions.   I will fix the accepted solution when the moderator opens this back up again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now