Gilly79 Posted February 6, 2010 Share Posted February 6, 2010 Hello Im building a site and want my users t obe able to amend there data Im okay with sessions etc - the only issue i am having is quite basic but for some reason im just not getting how to do it! I want to return the data for a selected customer into a form so they can amend it... Im okay with how to select a specific record, im also okay with what data to return, however i dont know how to return it into a form... Thats it really as I know what i need to do to update the record when amending is complete... This is the form i want to return the values to <form enctype="multipart/form-data" method="post" action="coursecheck.php"> <p> <label>CourseCode <input type="text" name="CourseCode" SIZE="5" MAXLENGTH="5" id="CourseCode" /> </label> * - Must Be Entered <label>Course Title <input type="text" name="CourseTitle" id="CourseTitle" /> </label> </p> <p> <label>The School Year <input type="text" name="Year" id="Year" /> </label> </p> <p> <label>Description of the course <textarea name="Description" cols="100" rows="5" id="Description"></textarea> </label> </p> <p> <label>Owner of the module <input type="text" name="Owner" id="Owner" /> </label> * - Must Be Entered </p> <p> <label>Tutor1 <input type="text" name="Tutor1" id="Tutor1" /> </label> * - Must Be Entered </p> <p> <label>Tutor2 <input type="text" name="Tutor2" id="Tutor2" /> </label> * - Must Be Entered </p> <p> <label>Tutor3 <input type="text" name="Tutor3" id="Tutor3" /> </label> * - Must Be Entered </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> many thanks Quote Link to comment https://forums.phpfreaks.com/topic/191144-returning-data-from-mysql-database-into-a-form-in-order-to-amend-data/ Share on other sites More sharing options...
wildteen88 Posted February 6, 2010 Share Posted February 6, 2010 To pre populate your input fields use the value html attribute, eg <input type="text" name="some name" value="some value" /> Quote Link to comment https://forums.phpfreaks.com/topic/191144-returning-data-from-mysql-database-into-a-form-in-order-to-amend-data/#findComment-1007872 Share on other sites More sharing options...
Gilly79 Posted February 6, 2010 Author Share Posted February 6, 2010 brilliant thank you very much that helps a lot - the next questio nis how do i address a variable returned from sql database in ther value field?? Ill show you what I have already as im returning the data for the users to view so they know what is held currently... Below im just trying to get the coursecode from the database <?php // set database server access variables: include "connection.php"; //Get the Search Criteria passed $query = "SELECT * from courses"; $CourseCode = $_GET["Search"]; if (!empty($CourseCode)) //Show just DJ searched for { print "Looking for a Course containing $CourseCode<br>"; // create query - This query combines data from the film table and the director table $query = $query." where CourseCode like '%$CourseCode'"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result)>0) { echo "<table border=1>\n<tr>" . "<th>CourseCode</th>" . "<th>CourseTitle</th>" . "<th>Year</th>" . "<th>Description</th>" . "<th>Owner</th>". "<th>Tutor1</th>". "<th>Tutor2</th>". "<th>Tutor3</th>"; while ($row = @ mysql_fetch_array($result)) { //while($row = mysql_fetch_row($result)) { echo "<tr>"; echo "<td class=BorderMeRed>".$row["CourseCode"]."</td>"; echo "<td class=BorderMeRed>".$row["CourseTitle"]."</td>"; echo "<td class=BorderMeRed>".$row["Year"]."</td>"; echo "<td class=BorderMeRed>".$row["Description"]."</td>"; echo "<td class=BorderMeRed>".$row["Owner"]."</td>"; echo "<td class=BorderMeRed>".$row["Tutor1"]."</td>"; echo "<td class=BorderMeRed>".$row["Tutor2"]."</td>"; echo "<td class=BorderMeRed>".$row["Tutor3"]."</td>"; echo "</tr>"; } echo "</table>"; } else { // print status message echo "No Records Found"; print date("j/m/y H:i", time()); } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <form enctype="multipart/form-data" method="post" action="courseamend.php"> <p> <label>CourseCode <input type="text" name="CourseCode" SIZE="5" MAXLENGTH="5" id="CourseCode" value="%$CourseCode" /> </label> * - Must Be Entered <label>Course Title <input type="text" name="CourseTitle" id="CourseTitle" /> </label> </p> Quote Link to comment https://forums.phpfreaks.com/topic/191144-returning-data-from-mysql-database-into-a-form-in-order-to-amend-data/#findComment-1007884 Share on other sites More sharing options...
wildteen88 Posted February 6, 2010 Share Posted February 6, 2010 You'll need to output your form fields within your while loop. For example <?php // set database server access variables: include "connection.php"; //Get the Search Criteria passed $query = "SELECT * from courses"; $CourseCode = $_GET["Search"]; if (!empty($CourseCode)) //Show just DJ searched for { print "Looking for a Course containing $CourseCode<br>"; // create query - This query combines data from the film table and the director table $query = $query." where CourseCode like '%$CourseCode'"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result)>0) { ?> <form enctype="multipart/form-data" method="post" action="courseamend.php"> <table border=1> <tr> <th>CourseCode</th> <th>CourseTitle</th> <th>Year</th> <th>Description</th> <th>Owner</th> <th>Tutor1</th> <th>Tutor2</th> <th>Tutor3</th> </tr> <?php while ($row = mysql_fetch_assoc($result)): ?> <tr> <td class=BorderMeRed> <label>CourseCode <input type="text" name="CourseCode" SIZE="5" MAXLENGTH="5" id="CourseCode" value="<?php echo $row["CourseCode"]; ?>" /> </label> * - Must Be Entered. </td> <td class=BorderMeRed> <label>Course Title <input type="text" name="CourseTitle" id="CourseTitle" value="<?php echo $row["CourseTitle"]; ?>" /> </label> </td> etc for all your form fields </tr> <?php endwhile; ?> </table> <p><input type="submit" name="button" id="button" value="Submit" /></p> </form> <?php } else { // print status message echo "No Records Found"; print date("j/m/y H:i", time()); } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/191144-returning-data-from-mysql-database-into-a-form-in-order-to-amend-data/#findComment-1007943 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.