Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Small simple mysql record editor

I have php code that connects to a MySQL database and grabs all the records I need. It then displays those records (one record per line - just text) on browser page. What I would like to do is add an edit button and a print button at the end of each of those records (note: the amount or records could vary from 30 to 200 any month). When the edit button is clicked, it opens a HTML Form, populates it with the data in that single record and only allows the user change a few things, when they are done making the needed changes, they click a save button which updates the MySQL database, and display the list of records again. If they click the print button - it display another html page and formats the record for printing, with another print button, when the print button is clicked, the page is set to a printer, and the original record list is displayed again.

I am not trying to ask that someone else code this (although if the wheel is already out there and offered I certainly would not ignore it!), just the best approach to take. I am familiar with PHP & HTML Forms, have never dove into JScript, or any of the other methods I might be able to use. All inputs are greatly appreciated.
I have tried using phpMyAdmin, and sidu - and the biggest problem I see with them is they have too much functionality for what I was hoping for.
 
0
NTNBower
Asked:
NTNBower
  • 5
  • 5
1 Solution
 
rdivilbissCommented:
Is your current display in a table or really just one line of text?
0
 
NTNBowerAuthor Commented:
I use a php page, and it connects to the database, query's the database and then dumps the results in php variable, then I loop through the variable and display 1 record per line, so it looks like:

FPO#: 123 Part#: 456 DueDate: 060608 NeedRoll: N NeedRace: N NeedRetain: N
FPO#: 456 Part#: 789 DueDate: 060608 NeedRoll: Y NeedRace: N NeedRetain: N
...

and that is whats displayed on the web page returned by the PHP code. I would like to add buttons to the end of each record, one button for Edit & one for Print - like:

FPO#: 123 Part#: 456 DueDate: 060608 NeedRoll: N NeedRace: N NeedRetain: N [Edit] [Print]
FPO#: 456 Part#: 789 DueDate: 060608 NeedRoll: Y NeedRace: N NeedRetain: N [Edit] [Print]
...

Clicking edit or print would open (goto) another page, I am thinking for edit I could just use a form to let them make their changes to NeedRoll, NeedRace, NeedRetain (boolean either yes or no) then it would connect to the MySql and submit their toggle changes to the MySQL database, and re-open the original list again (should be able to see their changes. As for the print button - it just opens (goes to)  a windows displaying the text in a report format for them to print out.

I could put the output into a table, but so far I just have text being echoed out.  
0
 
rdivilbissCommented:
No need for a table other than it might be neater.

Essentially you need the record's unique id for your button...

<input type="button" value="Edit" onclick="edit(record-id);">

Since you just wrote plain text, you'll need to call back and look up that record before you can edit, the call back (post) to update the info.  That's doable and is a better method if the is a likelihood of two people working on the same record at once.

Another method would be to write the data to the browser in a way you could directly gather the details needed to be editted, either as a JavaScript array or as part of the DOM (say a table) so you do not have to query again to get the record to edit.

With either method you'll need a new page that receives the posted data and updates the record.

Is JavaScript available?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rdivilbissCommented:
0
 
NTNBowerAuthor Commented:
I have never used JScript - while it looks very nice, I am just not familiar with it. I actually thought I would just loop through pages as needed, like show entire list of records with the edit buttons, if you click edit for that record - the whole page changes to the edit page for just that record (using the key to do another query to mysql, and display the editor page). when your done editing, clicking save would submit the MySQL changes, and reload (or call) the original php page again that should now show the changes. Just continueing like this for each record they need to change.
0
 
rdivilbissCommented:
Then you should use a hyperlink, rather than a button.

e.g. <a href="edit.php?id=123">edit</a>

And on the edit page, after a successful edit set the header location to the original page.
0
 
NTNBowerAuthor Commented:
What can I say - so many times you just cannot see the forest for the trees. Brilliant - thanks!
0
 
NTNBowerAuthor Commented:
Perfect - for me, I try and prove the concept - then the developers take it and make it pretty. This is going to work out just fine. Thanks again.
0
 
rdivilbissCommented:
I liked my fancy edit in place better ;-)
0
 
NTNBowerAuthor Commented:
So did I - however - liking and implementing are two very different things -) In the 10 minutes it took me to do the HTML solution - I don't think it could be beat. I am sure once the real developers get their hands on it - it will be Jscripted and prettified much more than my kiss (proof of concept) approach.

Thanks a ton.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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