karl_009 Posted February 17, 2009 Share Posted February 17, 2009 Hello again, I have been trying to get data from a database to be displayed in a form, I have three pages one to enter the data which is fine, I have a page the lets you view the data and on there is an update link to let you update the record via a form. However am at the stage where am trying to get the data to be displayed in the form here is the code am using so far; contact_view.php <?php require ($_SERVER['DOCUMENT_ROOT']."cmstesting/config/db_config.php"); $connection = @mysql_connect ($db_host, $db_user, $db_pass) or die ("Error with Connection"); mysql_select_db ($db_name, $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++) { $conid = mysql_result ($result, $i, "conid"); $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> <td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id='.$conid['conid'].'">Update</a> <font face="arial" size="2"> </font> </td> </tr> '; } ?> </table> </center> <body> </body> </html> An the code for viewing the data in a form, this is not the whole form only three fields of it so there is some missing HTML on here.. contact_edit.php <?php require ($_SERVER['DOCUMENT_ROOT']."cmstesting/config/db_config.php"); $connection = @mysql_connect ($db_host, $db_user, $db_pass) or die ("Error with Connection"); mysql_select_db ($db_name, $connection); // Get value from address bar $conid=$_GET['conid']; // Get data from database $query = "SELECT * FROM contacts WHERE conid='$conid'"; $result = mysql_query ($query); $rows = mysql_fetch_array ($result); <form id="contact" name="contact" class="" autocomplete="off" enctype="multipart/form-data" action="" method="POST"> <div class="info"> <h2>New Contact</h2> <div></div> </div> <ul> <li id="foli0" class=" "> <label class="desc" id="title0" for="Field0"> Name </label> <span> <input id="title" name="title" type="text" class="field text" value="" size="2" tabindex="1" /> <label for="Field0">Title</label> </span> <span> <input id="first" name="first" type="text" class="field text" value="<?php echo $rows['first']; ?>" size="8" tabindex="2" /> <label for="Field1">First</label> </span> <span> <input id="last" name="last" type="text" class="field text" value="<?php echo $rows['last']; ?>" size="12" tabindex="3" /> <label for="Field2">Last</label> </span> So here I sould see the out put of the first name and the last name... Thanks for any help.. Karl Link to comment https://forums.phpfreaks.com/topic/145614-solved-view-data-in-a-html-form-using-php-mysql/ Share on other sites More sharing options...
karl_009 Posted February 17, 2009 Author Share Posted February 17, 2009 Solved it... It was this line; <td width="10%" valign="top" bgcolor="'.$bg_color.'"><a href="contact_edit.php?id='.$conid['conid'].'">Update</a> I needed to change part of it to this; "contact_edit.php?conid='.$conid['conid'].'" ... Link to comment https://forums.phpfreaks.com/topic/145614-solved-view-data-in-a-html-form-using-php-mysql/#findComment-764484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.