Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP foreach loop to incorporate link

Posted on 2013-05-14
5
Medium Priority
?
305 Views
Last Modified: 2013-05-19
I'm having a problem with my php link operating correctly... I've listed below two code examples... one works correctly when I don't include "member_id" pulled from database within url link.... when I include "member_id" within url link, my page is not shown:

This link doesn't work:
foreach ($rowset as $row) {
            echo "<tr><td>" . htmlspecialchars($row['lastName']) . "</td><td>" . htmlspecialchars($row['firstName']) . "</td><td>" . htmlspecialchars($row['businessName']) . "</td><td>" . "<a href='index.php?page=admin-display-user&id=" . $row['member_id'] . "'>view</a></td></tr>";      
      }

This link does work:
foreach ($rowset as $row) {
            echo "<tr><td>" . htmlspecialchars($row['lastName']) . "</td><td>" . htmlspecialchars($row['firstName']) . "</td><td>" . htmlspecialchars($row['businessName']) . "</td><td>" . "<a href='index.php?page=admin-display-user&id='>view</a></td></tr>";      
      }
0
Comment
Question by:melvint91
  • 3
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39166468
I would assume $row['member_id'] doesn't exist.
What error do you get?
0
 
LVL 6

Expert Comment

by:nickinthooz
ID: 39166713
That has got to be the issue, there is nothing wrong with the format of the code.  Double check the name of your member_id field and make sure it's in the table you're pulling from.
0
 

Author Comment

by:melvint91
ID: 39166944
row [member_id] does exist because the "id #" is displayed when hovering over link... I'm not getting an error, a blank page is opening but without the content showing...
0
 

Accepted Solution

by:
melvint91 earned 0 total points
ID: 39166947
I resolved the issue. . .I changed the following to :

page=admin-display-user&id=" . $row['member_id']

changed to:

page=admin-display-user&member_id=" . $row['member_id']
0
 

Author Closing Comment

by:melvint91
ID: 39178306
I decided to try the change because I knew the $row['member_id'] was correct field in database.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

877 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