Jump to content

[help] Updating/Changing Database Information


zeromuswk

Recommended Posts

Here is what I have done and am doing;

 

I created a log in for members of my guild. There is a table in my database that stores the information. It is listed with ID, Login, Password, Character Name, Level, etc... Upon entering their login information, when correct it logs them in and goes to a 'login successful' page. When wrong information is entered it goes to a 'Login Incorrect' page.

 

What I want to do;

 

I want there to be a form that allows them to change certain fields in their section of the 'members' table. For example, if someone gains a level they can log in and submit their new level. I have the form already and the MySQL function that pulls the information from the form. What I can't do, however, is get the information to change in their section of the table. I have tried a few things including the UPDATE function. Could someone please help me? Maybe give me the correct command to have the information changed/updated? Start there perhaps and I can try it on my own.

 

Thanks in advance,

Zeromus

Link to comment
Share on other sites

Ok, thanks a lot. This helps very much. I guess the last question I have for now is, would it be possible to use the ID as the identifier?

 

WHERE ID = '1'");

 

Also, if I have that person (guess this is a second last question =) logged in, since it checks their username and password, how could I have the form I am using to update the information reflect the ID number associated with that particular person? For example, Admin logs in and the ID is 1. Tester logs in and the ID is 2. How do I get it to recognize Tester as ID 2 after he logs in? You know, the WHERE ID = 'x'"). I wouldn't want Admin logging in and it opening Tester's information field. Would I have to create a seperate page for each member?

 

Oh yeah (last question number three...), if I have a form that has, say, 6 text fields to submit data. How can I make it submit ONLY the data that needs to be changed? So if that particular person enters information in the LEVEL field but leaves the other fields empty. I don't want it to submit no data and overwrite the existing information.

 

Thanks again!

Link to comment
Share on other sites

Yes you can use the ID as the identifier, and since it should be set to auto increment, everyone will have their own unique ID. It's actually how you should identify them. If you make other tables that need to refer to users, you can make a column called userid or something, and refer to that ID.

 

Your second and third question tie in some php (if that's what you're using)

 

You're gonna run a query to grab the results on login, which you may have something basic already? Should be similar to this:

$result = mysql_query("SELECT * FROM users WHERE username='username_input' AND password='password_input'");

while($row = mysql_fetch_array($result))
  {
  $userid = $row['ID'];
  }

 

This is where I set my sessions, when there is a match, I grab the id and set the session with that. (I use sessions, I'm not sure how you're doing it, just mentioning this)

 

Third question, what you wanna do is check if it is empty or not and then do something from there. So before your query you run some php tests

if (empty($_POST['username'])){
$username = $username;
} else {
$username = $_POST['username'];
}

 

Something along those lines, then your "$username" variable is set to either what it previously was, or what they want it changed to. Then run an UPDATE query on all the rows that they have options to change. There are a few ways to do it, this is how I would probably do it.

Link to comment
Share on other sites

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.