PDA

View Full Version : MySQL (and PHP) help needed


Dark Jim
08-29-2002, 11:14 PM
I'm working on a RPG hack and created a new table called "rpg_user". In that table you have "userid" and various stuff such as "exp", "hp" and more. I created a file "rpgadmin.php" and now when $action=modifyuser you can enter the name of the user you want to edit. I can't figure out how to get all data from that user in the table "rpg_user" by entering a name. Could someone help? :ermm: Note that I know almost no php or mysql and this is just trying and seeing what happens what I'm doing. :p Although by doing so and by looking at other's code you'll learn too. :)

Btw here is what I have so far. Also I want it so that after you modified options, the page should go back to "options" and when you editted a user the page should go back to "modifyuser". I looked at how this was done in other hacks but still I can't get it working. :(
<?php



error_reporting(7);
require("./global.php");
cpheader();

if (isset($action)==0) {
$action="options";
}

// ###################### Edit options #######################

if ($action=="options") {

doformheader("rpgadmin","updateoptions");

$rpgopt=$DB_site->query_first("SELECT * FROM rpg_options");

if ($rpgopt[enable]=="1") {
$enableyes="checked";
$enableno="";
} else {
$enableyes="";
$enableno="checked";
}

maketableheader("Edit RPG Options","",0);

echo "<tr class='".getrowbg()."' valign='top'>";
echo "<td><p>Enable RPG feature</p></td>";
echo "<td><p>Yes<input type='radio' name='enable' value='1' $enableyes> No <input type='radio' name='enable' value='0' $enableno></p></td></tr>";

doformfooter('Save changes');

}

// ###################### Update Options #######################

if ($action=="updateoptions") {

$DB_site->query("UPDATE rpg_options SET enable=$enable");

echo "<p>RPG Options updated!</p>";

$action="options";

}

// ###################### Modify user #######################

if ($action=="modifyuser") {

doformheader("rpgadmin","edituser");

makeinputcode("User Name contains","ausername");

doformfooter('Edit User');

}

// ###################### Edit user #######################

if ($action=="edituser") {

doformheader("rpgadmin","updateuser");

$userstats=$DB_site->query_first("SELECT <What goes here?> ");

makeinputcode("Experience","exp","$userstats[exp]");

doformfooter('Save changes');

}

// ###################### Update Selected user #######################

if ($action=="updateuser") {

$DB_site->query("UPDATE rpg_user SET exp=$exp WHERE userid=$auser");

echo "<p>RPG User Options updated!</p>";

$action=="edituser";

}

cpfooter();
?>

g-force2k2
08-30-2002, 12:17 AM
A :: for the SELECT * FROM rpg_options if the table doesn't exist it doesn't help unless you have both an rpg_options and rpg_user

for the other query that you don't know same concept ::

...$DB_site->query_first("SELECT * FROM rpg_user WHERE...

hope that helps ;) regards...

g-force2k2

Dark Jim
08-30-2002, 07:29 AM
Heh, found out what I was doing wrong. I tried to select the stuff "WHERE userid=$auser but it had to be "WHERE userid=$auser[userid]. Also I had to add makehiddencode for the userid otherwise the update wouldn't work. So now the updated part is
// ###################### Edit user #######################

if ($action=="edituser") {

doformheader("rpgadmin","updateuser");

$auser=$DB_site->query_first("SELECT userid FROM user WHERE username='$ausername'");
$userstats=$DB_site->query_first("SELECT * FROM rpg_user WHERE userid=$auser[userid]");

makeinputcode("Experience","exp","$userstats[exp]");
makehiddencode("auser","$auser[userid]");

doformfooter('Save changes');

}

// ###################### Update Selected user #######################

if ($action=="updateuser") {

$DB_site->query("UPDATE rpg_user SET exp=$exp WHERE userid=$auser");

echo "<p>RPG User Options updated!</p>";

$action=="edituser";

}
and it all works fine. Now I can add more options. :)