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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

PHP - Syntax passing record id

Learning PHP and I don't have problems with the difficult concepts but the syntax is the worst language I have dealt with.  I can't get the passing of the URL id code to pass the syntax test.  I'm sure it is easy for experienced PHP coders -  If you notice the image code on the last line - I went through the same thing getting it to pass the syntax test.  I am modifying a program with a feature I want from another program and they coded things differently.

Thanks

  echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td>' <a href='info.php?id=".$row['id']."'>".$row['lastname']."</a>'</td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td> <img src="'. $row['s_img']. '" width="102" height="111"/></td>';

Open in new window

0
JohnMac328
Asked:
JohnMac328
  • 4
  • 4
1 Solution
 
GaryCommented:
                echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td> <a href="info.php?id='.$row['id'].'">'.$row['lastname'].'</a></td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td> <img src="'. $row['s_img']. '" width="102" height="111"/></td>';

Open in new window

0
 
JohnMac328Author Commented:
Thats my question - I can't fix the syntax error
0
 
GaryCommented:
The code is fixed in that comment

Sometimes it makes more sense to drop out of the PHP parse and do it this way.

%>
                <tr>
                <td><?=$i?></td>
		<td> <a href="info.php?id=<?=$row['id']?>"><?=$row['lastname']?></a></td>
                <td><?=$row['lastname']?></td>
                <td><?=$row['firstname']?></td>
                <td><?=$row['email']?></td>
                <td><?=$row['phonenumber']?></td>
		<td> <img src="<?=$row['s_img']?>" width="102" height="111"/></td>

Open in new window


(This is assuming open_tag is enabled)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
JohnMac328Author Commented:
I guess I better add more code since it is changing so much - so how would it work with all of this

 while ($row = mysql_fetch_array($sql)) {
                // Print out the contents of the entry 
				
				
                echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td>' <a href='info.php?id=".$row['id']."'>".$row['lastname']."</a>'</td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td> <img src="'. $row['s_img']. '" width="102" height="111"/></td>';
                $i++;
            }
 } 
else 

Open in new window

0
 
GaryCommented:
while ($row = mysql_fetch_array($sql)) {
                // Print out the contents of the entry 
          	echo '<tr>';
                echo '<td>' . $i . '</td>';
		echo '<td><a href="info.php?id='.$row['id'].'">'.$row['lastname'].'</a></td>';
                echo '<td>' . $row['lastname'] . '</td>';
                echo '<td>' . $row['firstname'] . '</td>';
                echo '<td>' . $row['email'] . '</td>';
                echo '<td>' . $row['phonenumber'] . '</td>';
		echo '<td><img src="'. $row['s_img']. '" width="102" height="111"/></td>';
		echo '<tr>'; 
                $i++;
            }
 } 
else

Open in new window

0
 
JohnMac328Author Commented:
Great thanks - Do you know of any good sites with examples of different PHP coding to decipher the syntax problem I am running into?
0
 
GaryCommented:
php.net has samples for all its functions.
Your problem above is very, very common when dealing with apostrophes and speech marks, even I screw up with it sometimes.
0
 
JohnMac328Author Commented:
Thanks Cathal!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now