Jump to content

Recommended Posts

I have a decent site running using html and javascript. I am moving to a host that supports mysql and php and want to incorporate those features.

 

I have a Members Table which I maintain and is hard coded using html. Now I want to change it where the Member User has the ability to maintain his own information.

 

I basically understand the coding to create the database, the table and to insert and/or change the Member Data using Form input. But I don't want to use forms.

 

Here is what I would like to do:

 

1.  Display the Members data using the table I currently have.

2.  Maybe have a buttom that says "Modify Data."

3.  Have the user enter the "ID" of the row he wants to modify. Or, could I just have him click somewhere on the row he wants to modify?

4.  Update the database table.

5.  Redisplay the table with the new data.

 

I guess my problem is I don't understand how to use a table for input vs. a form.

 

Something like the flowchart steps would be greatly appreciated.

1.  Display the Members data using the table I currently have.

You can easily add php variables to a html table like this:

<table>
  <tr>
    <td>Username</td>
    <td>Email</td>
  </tr>
  <tr>
    <td><?php echo $username; ?></td>
    <td><?php echo $email; ?></td>
  </tr>
<table>

You would most likely include html like that in a php loop http://www.w3schools.com/php/php_looping.asp to show each user in a database.

Or if you want a similar table, that just shows one user, it's even easier. Just read the MySQL tutorial here http://www.w3schools.com/php/php_mysql_intro.asp

2.  Maybe have a button that says "Modify Data."

Again, you can have a button that links to something like edit_user.php?user=ttocskcaj that way the php script can know that the user you are modifying is called ttocskcaj, and in turn, knows what table row to update into. As you may know, this is called the get method.

edit_user.php would probably contain a html form of some time, you can use something like

<input value="<?php echo $username; ?>" name="username">

to show the original data in your table. Which makes it easier to change.

Again, read the MySQL tutorial on how to update a MySQL row.

3.  Have the user enter the "ID" of the row he wants to modify. Or, could I just have him click somewhere on the row he wants to modify?

You probably don't want a user modifying other users, but again you can use the get method to show a form aimed at editing one user.

5.  Redisplay the table with the new data.

After you update the database with new data from a html form, you can use a php redirect like this:

header("location:index.php")

Note that php headers need to be send before a HTML tag is sent, so the page that updates the database, like update_user.php or whatever you want, shouldn't print anything on screen.

 

In short,

1. The php script draws a table and fills it with php variables pulled from the database for each user as it goes (loop). This table will include a link to edit that row.

2. The column could be a link to that users own table, again using the get method like view_user.php?user=ttocskcaj

3. At the bottom of that page, there will be a link for that user to update their info. php will draw a html form and fill it with the  current data, making it easy to see what you need to update. When the form is sent, the data will be put into the database using MySQL UPDATE (tutorial again). Then the user will be redirected back to the main table with a php redirect.

 

Hope that helps, and isn't too confusing!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.