Jump to content

inserting query result into a form?


rattlsnak

Recommended Posts

<same project, more questions!>I want to run a query which selects data from the DB and outputs it onto a page that can then be user editable and then run another query to update their info. I have made a form where the user selects their ID and when submitted, their info is diplayed in a table. I want them to be able to make changes and then submit their new info to the DB to be updated. SO instead of displaying their data into a table, I /assume/ it would have to go into various textfields in a form, where they can make changes and a submit button would then query the update. I have made a form with the textfields but dont know how to display their selected info into that form's textfields. As you can see below, I have it displayed in the same table cell as the textfield, but that area is not editable to the user, as it is not in the text field area. I tried moving the echo statement to the beginning, but then it just goes in front of the textfield. So how can I do this?I also have a few questions on the UPDATE query, but let's get this part working first!Thanks,n00b!<form action="update.php" method="post" name="form5" class="style9" id="form5"> <table width="600" border="1" align="center" cellpadding="1" cellspacing="1"> <tr> <td class="style9">Player Last Name:</td> <td class="style9"><input name="l_name" type="text" id="l_name" size="35" /><?php echo $row['l_name']?></td> </tr> <tr> <td class="style9">Team:</td> <td class="style9"><input name="team" type="text" id="team" size="35" /><?php echo $row['team']?></td> </tr> <tr> <td class="style9">Division:</td> <td class="style9"><input name="div" type="text" id="div" size="25" /><?php echo $row['div']?></td> </tr> <tr> <td colspan="2" class="style9"><div align="center"> <input name="Submit" type="submit" id="Submit" value="Submit" /> </div></td> </tr> </table> </form>

Link to comment
Share on other sites

Thanks!That worked in all the fields except the comments , which is a text area, not a text field. (I know I didn't put that in the top posting!!) I thought they would all be the same. I tried it like this, but it wont display the comments. Is there a different value for the text area?<td class="style9"><input name="div" type="text" id="div" value="<?php echo $row['div']?>"/></td> </tr> <tr> <td class="style9">Comments:</td> <td class="style9"><textarea name="comments" cols="50" rows="4" id="comments" value="<?php echo $row['comments']?>"></textarea></td>EDITOK, I'm a n00b, i see how now..<td class="style9"><textarea name="comments" cols="50" rows="4" id="comments"><?php echo $row['comments']?></textarea></td>

Link to comment
Share on other sites

It is a little odd that the syntax for certain form elements differs. The new button tag, e.g., works like a textarea, not like the old <input type="button">.The Reason behind the textarea, simply, is that they can hold a lot of text -- awkward in an attribute assignment. Also, the text is preformatted, so a linebreak is signalled with a line break, not a "\n" -- impossible in a javascript assignment, where a line break would be read as a statement terminator.And yet! In javascript, you access the text of a textarea through the value property. It's easy once you learn it, but the differences are not intuitive.

Link to comment
Share on other sites

OK, all that is working now. Last issue is how to UPDATE what they have changed. $query="UPDATE bandits (l_name,team,div,comments) VALUES ('$_name', '$team', '$div, '$comments')";I need something along those lines. I was reading something about a SET and a WHERE clause, but that seems to be more item specific, as in updating just one value, where I need it to update one or all of the 4 fileds that the user could change. Since I have queried the db to get the results to get to the input page, when I submit the form, should it update the record it has pulled, or do I need to specify a specific ID again?

Link to comment
Share on other sites

If I understand you, it goes like this. Step 1. You run a script to generate the input form using queries to your DB. Step 2. The user submits the form. Step 3. A script intercepts the user's submission and goes back to the DB.At the end of Step 1, your script closes the DB and all references to it. Step 3 needs to open the DB from scratch.Using sessions, you can keep some user data persistent, and that can simplify Step 3, but you still have to open the DB.As far as your server can tell (unless you say otherwise) Step 1 and Step 3 are happening weeks apart. Many scripts could have been run, and other DBs opened, in the meantime. So you need to go through all the steps. Even if, in practice, the steps are occuring just 30 seconds apart.

Link to comment
Share on other sites

You are correct in the path of what happens. I think I understand what you are saying, but I am doing this on the same page with sessions, so I thought once the db opens with a connect script at the top of the page, it can stay open, regardless of how many queries are run on it for that page, so i have not been closing the database. I know for a simple page like this, it probably doesnt matter, but I agree in practice as page functions grow, this would be best. I can certainly add a closing script for step 1 and a connect script before step 3, but I what I don't know how to do is write the query on how to update the record based on my application.Thank you for your time!

Link to comment
Share on other sites

The more I think about it, my page setup is like this.. page 1. user enters id numberpage 2. when user hits submit on page 1, the form action takes it here and user info displayed in editable formpage 3. when user hits submit button on page 2, the form action takes it to here, where the script is runpage 4. echo "results updated" along with other html stuff on this page.I know i could probably do all this on one page, but didnt know how to seperate the submit buttons for the different forms and by using templates or includes, but the site was built a few years ago and I am only adding the members section.So, it may be a long roundabout way, but its working so far! I have learned aot here so far as to how I would make my next site for sure!But for now, I just need to write the UPDATE query and Ill be done!!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...