grlayouts Posted May 16, 2007 Share Posted May 16, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/ Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254436 Share on other sites More sharing options...
grlayouts Posted May 16, 2007 Author Share Posted May 16, 2007 ??? Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254438 Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 what are you looking for exactly ? Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254444 Share on other sites More sharing options...
grlayouts Posted May 16, 2007 Author Share Posted May 16, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254447 Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254450 Share on other sites More sharing options...
grlayouts Posted May 16, 2007 Author Share Posted May 16, 2007 one whats UID and 2 there is no post code? Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254452 Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 UID = Unique IDentity No post code.. erm i think you many need to check that! OK lets start again whats the problem with your code ? Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254455 Share on other sites More sharing options...
SoulAssassin Posted May 16, 2007 Share Posted May 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254458 Share on other sites More sharing options...
nikkieijpen Posted May 16, 2007 Share Posted May 16, 2007 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'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254459 Share on other sites More sharing options...
SoulAssassin Posted May 16, 2007 Share Posted May 16, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254461 Share on other sites More sharing options...
grlayouts Posted May 16, 2007 Author Share Posted May 16, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254464 Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 OMG.. ok well if you don't know the basics maybe the freelance section is a better place, or a book store.. we are NOT going to write your site for you! Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254466 Share on other sites More sharing options...
SoulAssassin Posted May 16, 2007 Share Posted May 16, 2007 Hey Dude, this is Open Source, not Free Services. Please do some research before asking the most basic questions. People won't mind helping if you get stuck, but you have no clue. Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254469 Share on other sites More sharing options...
grlayouts Posted May 16, 2007 Author Share Posted May 16, 2007 so pasremarkable. i do VB programming, instead of helping you bitch. clever Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254515 Share on other sites More sharing options...
MadTechie Posted May 16, 2007 Share Posted May 16, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/51654-update-help/#findComment-254538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.