Hey everyone. Im trying to make an online RPG where you can join "Families" or clans. I the code below is what I have thus far. It works but for some reason it wont update the creating users "family_id" in the database thus not telling the server that he is associated with any family. Can anyone take a look at the below code and help me out? Thanks.
<!--Add new family page-->
<form action="process.php" method="POST">
Family Name:<br>
<input type="text" name="familyname" maxlength="30" value="<?php echo $form->value("familyname"); ?>"><?php echo $form->error("familyname"); ?>
<br>
Family Description:<br>
<textarea name="familydesc" rows="6" cols="50" value="<?php echo $form->value("familydesc"); ?>"></textarea><?php echo $form->error("familydesc"); ?><br>
<input type="hidden" name="subnewfamily" value="1">
<input type="submit" value="Create new family">
</form>
//Process.php
function procNewFamily()
{
global $session, $form;
//New family creation attempt
$retval = $session->newFamily($_POST['familyname'], $_POST['familydesc']);
//New family creation successfull
if($retval)
{
$_SESSION['newfamily'] = true;
header("Location: index.php?page=familyinfo");
}
//Error found with form
else
{
$_SESSION['newfamily'] = false;
$_SESSION['value_array'] = $_POST;
$_SESSION['error_array'] = $form->getErrorArray();
header("Location: index.php?page=newfamily");
}
}
//Session.php
function newFamily($subname, $subdesc)
{
global $database, $form; //The database and form object
//Family name error checking
$field = "familyname";
if(!$subname)
{
$form->setError($field, "* Please enter a Family Name.");
}
//Family description error checking
$field = "familydesc";
if(!$subdesc)
{
$form->setError($field, "* Please enter a description.");
}
if($form->num_errors > 0)
{
return false; //Errors with form
}
else
{
$database->addNewFamily($subname, $subdesc, $this->username, $this->userid);
return true;
}
}
//database.php
function addNewFamily($family_name, $family_desc, $username, $userid)
{
//Create new family
$q = "INSERT INTO ".TBL_FAMILIES." VALUES ('$family_name', '0', '$family_desc', '$userid')";
mysql_query($q, $this->connection);
//Get family ID
$q = "SELECT family_id FROM ".TBL_FAMILIES." WHERE family_name = '$family_name'";
$id = mysql_query($q, $this->connection);
//Update creating users family ID associating him with that family
//$this->updateUserField($username, 'family_id', $id);
$q = "UPDATE ".TBL_USERS." SET family_id = '$id' WHERE username = '$username'";
return mysql_query($q, $this->connection);
}
I think the last part in database.php is where I'm going wrong. it seems right to me but it wont update the field "family_id" in TBL_USERS. TBL_USERS has been properly defined in constants.php which is included at the top of database.php. Anyy suggestions?? Thanks.