Jump to content

update help.


grlayouts

Recommended Posts

when i load in a players account i want to be able to change there stats by typing them in and hitting edit

 

the code i have is

 

<?php $title = "Admin Panel"; include("header1.php"); ?>
<form method=post action=admin2.php?view=account&step=lookup>ID: <input type="text" name="id"><input type="submit" value="Edit"><input type=hidden value=edit name=action></form>
<p>
  <? if ($step == lookup) {  ?>
<table>
      <td width="50%">Username:</td>
        <td width="50%"><input type="text" name="job" size="40" value="<?=$stat[user]?>"></td>
  </tr>
  <tr>
    <td width="50%">Password:</td>
    <td width="50%"><input type="text" name="pass2" size="30" value="<?=$stat[pass]?>"></td>
  </tr>
  <tr>
    <td>Age:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[age]?>">
      days</td>
  </tr>
  <tr>
    <td>Round Age:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[rage]?>">
      days</td>
  </tr>
  <tr>
    <td>Money:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[credits]?>">
      Credits</td>
  </tr>
  <tr>
    <td>Job:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[job]?>"></td>
  </tr>
  <tr>
    <td>Income:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[income]?>">
      Credits</td>
  </tr>
  <tr>
    <td>Strength:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[strength]?>"></td>
  </tr>
  <tr>
    <td>Agility:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[agility]?>"></td>
  </tr>
  <tr>
    <td>Knowledge:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat[knowledge]?>"></td>
  </tr>

</table>
<? } ?>
[code]


so say i wanted to chnage knowledge from the 200 it loads in to 300 how would i do this?

[/code]

Link to comment
Share on other sites

When i load in an account.

 

if i change for example the text field rage from 20 to 30. i want it to update the database.

 


   <td>Round Age:</td>
    <td><input type="text" name="rage" size="5" value="<?=$stats[rage]?>">
      days</td>
  </tr>
  <tr>

Link to comment
Share on other sites

And the problem with this code is ?

 

something like

 

<?php
if(isset($_POST['UID']))
{
mysql_query("UPDATE table SET name = `{$_POST['name']}, lastname= `{$_POST['lastname']} WHERE UID={$_POST['UID']}`");
}
?>

 

add a hidden field for the UID

 

just a basic how to

Link to comment
Share on other sites

No Dude, your page doesn't even do a select to get your $stat[knowledge]

Your fields are also outside your <form>

 

U'd have to put this on top before you can UPDATE the table

if(isset($_POST['Edit'])) 
{
//obviously all the fields you need to change
$knowledge = $_POST['knowledge'];
$id = $_POST['knowledge'];
$result = mysql_query("Update yourtable set knowledge='$knowledge' where id=".$_POST['id']);
$edit = "";
}

 

You should first SELECT a entry from the Table.

Then your form should look more like this:

//first you'd need to have $id set in some way
$result = mysql_query("Select * from yourtable WHERE id = '$id'");
$stat = mysql_fetch_array($result);
<td><input type="text" name="age" size="5" value="<? echo $stat[knowledge]; ?>"></td>
       <input type="hidden" value="<? echo $stat['id']; ?>" name="id">

 

But I honoustly think you should go read up on it first.

Link to comment
Share on other sites

MadTechie is right. You have use a hidden field which contains a user ID so your scripts knows which record it has to update. Also put the table inside the form and add a submit button. You also have al your textfield named "age". Give every textfield a unique name. PHP will use that name to extract the value out of it. Once you submit the form it creates a $_POST['textfieldname'] variable to store in the value of that particular textfield.

 

Here's a code sample:

 

<form method="post" action="updateStats.php">
<table>
  <tr>
    <td>Age:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat['age']?>" /></td>
  </tr>
  <tr>
    <td>Knowledge:</td>
    <td><input type="text" name="knowledge" size="5" value="<?=$stat['knowledge']?>" /></td>
  </tr>
  <tr>
    <td>Submit the form:</td>
    <td><input type="submit" name="sumbit" value="Submit" /><input type="hidden" name="userID" value="<?=$stat[userID]?>" /></td>
  </tr>
</table>
</form>

 

updateStats.php:

<?php
if(isset($_POST['userID'])) {
  $knowledge = $_POST['knowledge'];
  $usID = $_POST['userID'];
  $age = $_POST['age'];
  mysql_query("UPDATE table SET knowledge =  'knowlegde', age = '$age' WHERE userID = '$usID'");
}
?>

 

Link to comment
Share on other sites

And all your Form Fields are called "age"...

 

<tr>

<td>Age:</td>

<td><input type="text" name="age" size="5" value="<?=$stat[age]?>">

      days</td>

</tr>

<tr>

<td>Round Age:</td>

<td><input type="text" name="age" size="5" value="<?=$stat[rage]?>">

      days</td>

</tr>

<tr>

<td>Money:</td>

<td><input type="text" name="age" size="5" value="<?=$stat[credits]?>">

      Credits</td>

</tr>

Link to comment
Share on other sites

MadTechie is right. You have use a hidden field which contains a user ID so your scripts knows which record it has to update. Also put the table inside the form and add a submit button. You also have al your textfield named "age". Give every textfield a unique name. PHP will use that name to extract the value out of it. Once you submit the form it creates a $_POST['textfieldname'] variable to store in the value of that particular textfield.

 

Here's a code sample:

 

<form method="post" action="updateStats.php">
<table>
  <tr>
    <td>Age:</td>
    <td><input type="text" name="age" size="5" value="<?=$stat['age']?>" /></td>
  </tr>
  <tr>
    <td>Knowledge:</td>
    <td><input type="text" name="knowledge" size="5" value="<?=$stat['knowledge']?>" /></td>
  </tr>
  <tr>
    <td>Submit the form:</td>
    <td><input type="submit" name="sumbit" value="Submit" /><input type="hidden" name="userID" value="<?=$stat[userID]?>" /></td>
  </tr>
</table>
</form>

 

updateStats.php:

<?php
if(isset($_POST['userID'])) {
  $knowledge = $_POST['knowledge'];
  $usID = $_POST['userID'];
  $age = $_POST['age'];
  mysql_query("UPDATE table SET knowledge =  'knowlegde', age = '$age' WHERE userID = '$usID'");
}
?>

 

 

 

how can i load an account using that?

Link to comment
Share on other sites

I also do VB3-8, the fact is don't seam to understand the basics, each pages is like a class, if you know OOP then you can adapted

however noobies are welcome, rudness isn't.. good luck

 

Techie Out!

 

PS that code had basic logic mistakes.. no matter what language you use!

 

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.