Jump to content

more questions


xoligy

Recommended Posts

Alliance Questions:

 

Hey all back again for more help, i'll try and explain what im trying to do and see if you understand or not.

 

1. When a person creates an alliance on the page im working on I need it to insert all the info like alliance name, username, and id oh and the join code! Then update the userdetails with the alliance name. I did do a query like the one below for this which failed but is there a better way I could do this? (When I say failed I mean just the second query failed)

 

<?
if ($alliance){
$q="INSERT INTO `alliances` (`alliance`, `mid`, `founder`, `members`, `joincode`) VALUES ('$alliance', '$mid', '$fdr', '1', '$code')";
echo "$q<br>";
$r=@mysql_query($q);
$q="UPDATE `UserDetails` SET `alliance`='$alliance' WHERE `ID`=`$mid`";
echo "$q<br>";
$r=@mysql_query($q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysql_error);
}}
?>

 

2. I need to attempt to write some code that when the join link is entered in the address bar/clicked that the user thats logged in at the time join the alliance he chose, I then need to update the the members in the alliances table and then there userdetails with the alliance tag hence the question above.

3. After that im stuck with this query, basically I need the ID from alliances where the name is equal to the user->alliance I then need to put the id where $id is I understand how to do some simple querys but getting the results im lost because every ebook and book use the “mysql_fetch_array” command which you can see below lol

<?
                    $q="select ID from alliances where name=$user->alliance";
                    echo "$q<br>";
                    $r=@mysql_query($q);
                    if ($r) {
                    while ($row = mysql_fetch_array($r, MYSQL_BOTH)){
                    $id=$row['ID'];
                    }}            
                    if ($user->alliance){
                        $userA=getUserDetails($user->alliance,'alliance');
                        echo"<a href='alliance.php?id=$id'>$user->alliance</a>";
                    }else{
                        echo"None"; }
                    ?>

 

 

 

 

Ok it seems im having no luck at all the code below did work when I wrote the above but now it dont and I dont know what ive done or why it dont work! Whats the problem, Well the $fdr and $mid are not getting inserted into the db. Infact there not even getting echoed out with <?=fdr?> but if I type <?=$user->userName?> then it works strange I know anyone have any clues to what ive done :/

 

<?
$fdr = $user->userName; //get username
$mid = $user->ID; //get member id
    
if ($cgi['submit']) {
    if (!$cgi['name']){
      $error= 'Please enter an alliance name';
    }elseif (strlen($cgi['name'])< 2){
      $error= "Alliance name must be 2 or more characters";
    }elseif (chkalliance($cgi['name'])){
      $error= "That alliance name is already taken";
   // }elseif (chkfounder($cgi['name'])){
   //   $error="You are already the owner of an alliance";
   // }elseif (alrdymember($cgi['name'])){
   //   $error= "Your already in an alliance";
    }else{
    $alliance = trim(strip_tags($cgi['name']));
    $code = md5(uniqid(rand(), true));

if ($alliance){
$q="INSERT INTO `alliances` (`name`, `mid`, `founder`, `members`, `joincode`) VALUES ('$alliance', '$mid', '$fdr', '1', '$code')";
echo "$q<br>";
$r=@mysql_query($q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysql_error);
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/117818-more-questions/
Share on other sites

Okay I have some questions...

 

1. About the first question, what does MySQL say? What is the error that is returned? This information is always helpful.

2. How are the members stored in the members field, are they separated by a comma or something?

3. You shouldn't need to run mysql_fetch_array() in a while loop there, as alliance names are (I presume) unique. Here is a *possible* fix to that code:

if($user->alliance){
$q = "SELECT ID FROM alliances WHERE name={$user->alliance}";
echo "$q<br>";

$r=@mysql_query($q);

if ($r) {
$row = mysql_fetch_array($r);
$id = $row['ID'];
}
$userA=getUserDetails($user->alliance,'alliance');
echo"<a href='alliance.php?id=$id'>$user->alliance</a>";

}else{
echo "None";
}

Link to comment
https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-607393
Share on other sites

Notice: Query: the query

MySQL Error in alliances.php on line 85

 

85 is $r=@mysql_query

 

2. I was just going to insert the alliance name to the user details and updave the members with a +1 then come and ask for help on restricting access to other alliances if they dont have cm alliance or are already in one do u think i should add the users id to the alliance table? If so i'll have to fine out how to do that tomorrow when i im town im using my mobile atthe mo

 

Forgot to say the fix failed tried to echo out the id no good

Link to comment
https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-607451
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.