karl_009 Posted February 17, 2009 Share Posted February 17, 2009 Hi, I have a form that I have set up to INSERT data into, now am trying to set it up so that I can edit the data that has been entered. My table output is via an echo which out puts all the table but I need to execute a small PHP script from there so that I can click on the update link and the row for data is selected from the database. Here is the code; // Database Connection <html> <title>View Contacts</title> <center> <table bgcolor="#0066FF" border="0" width="75%" cellspacing="1" cellpadding="2"> <?php // Query for displaying data in the order of the persons last name $query = "SELECT * FROM contacts ORDER BY last"; $result = mysql_query ($query, $connection); for ($i = 0; $i < mysql_num_rows ($result); $i++) { $first = mysql_result ($result, $i,"first"); $last = mysql_result ($result, $i,"last"); $company = mysql_result ($result, $i,"company"); $town = mysql_result ($result, $i,"town"); $email = mysql_result ($result, $i,"email"); $email_len = strlen($email); if ($i % 2) { $bg_color="#EEEEEE"; } else { $bg_color="#AAAAAA"; } echo ' <tr> <td width="30%" bgcolor="'.$bg_color.'"> <font face="arial" size="2">'; if ($email_len > 0) { echo '<b>First Name:</b> <a href="mailto:'.$email.'">'.$first.'</a>'; } else { echo '<b>First Name:</b> '.$first; } echo ' <br> <b>Last Name:</b> '.$last.' </font> <td> <td width="20%" valign="top" bgcolor="'.$bg_color.'"> <font face="arial" size="2"> <b> Email: </b> '.$email.' </font> </td> <td> <td width="20%" valign="top" bgcolor="'.$bg_color.'"> <font face="arial" size="2"> <b> Town: </b> '.$town.' </font> </td> <td> <td width="20%" valign="top" bgcolor="'.$bg_color.'"> <font face="arial" size="2"> <b> Company: </b> '.$company.' </font> </td> <td> // This is the line where I am trying to run this code within the echo... <td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id=<?php echo $rows['id'];?>">Update</a> <font face="arial" size="2"> </font> </td> </tr> '; } ?> </table> </center> <body> </body> </html> <td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id=<?php echo $rows['id'];?>">Update</a> Many Thanks for any help Karl Quote Link to comment https://forums.phpfreaks.com/topic/145587-solved-execute-php-code-from-within-an-echo/ Share on other sites More sharing options...
Philip Posted February 17, 2009 Share Posted February 17, 2009 I don't understand why you're having trouble with that, when the rest of your code does it just fine. echo '<td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id='.$rows['id'].'">Update</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/145587-solved-execute-php-code-from-within-an-echo/#findComment-764329 Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 <td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id=<?php echo $rows['id];?>">Update</a> You are using <?php tags inside of an echo. Concat it like King has done, or like you have done previously and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/145587-solved-execute-php-code-from-within-an-echo/#findComment-764331 Share on other sites More sharing options...
karl_009 Posted February 17, 2009 Author Share Posted February 17, 2009 I feel silly now LOL, Am still new at all this PHP, didn’t realise it could be done in that way as well, something I wont soon forget. Thanks for the help Karl Quote Link to comment https://forums.phpfreaks.com/topic/145587-solved-execute-php-code-from-within-an-echo/#findComment-764332 Share on other sites More sharing options...
Philip Posted February 17, 2009 Share Posted February 17, 2009 It happens to the best of us Quote Link to comment https://forums.phpfreaks.com/topic/145587-solved-execute-php-code-from-within-an-echo/#findComment-764333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.