xoligy Posted August 2, 2008 Share Posted August 2, 2008 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 More sharing options...
xoligy Posted August 2, 2008 Author Share Posted August 2, 2008 No one able to help?:-S Link to comment https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-606139 Share on other sites More sharing options...
LemonInflux Posted August 2, 2008 Share Posted August 2, 2008 Dude, it's a saturday ---------------- Now playing: Linkin Park & Jay-Z - Big Pimpin'/Papercut via FoxyTunes Link to comment https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-606157 Share on other sites More sharing options...
xoligy Posted August 2, 2008 Author Share Posted August 2, 2008 lol true i forgot, guess i'll bump the post on monday Link to comment https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-606181 Share on other sites More sharing options...
xoligy Posted August 4, 2008 Author Share Posted August 4, 2008 Bump - i fixed the last error the code went on strike i spoke to there union :-D Link to comment https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-607388 Share on other sites More sharing options...
JasonLewis Posted August 4, 2008 Share Posted August 4, 2008 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 More sharing options...
xoligy Posted August 4, 2008 Author Share Posted August 4, 2008 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 More sharing options...
xoligy Posted August 4, 2008 Author Share Posted August 4, 2008 Is there a way to echo out something in a dropdown box depending on whats selected before anything is submitted? So say there are 2colours in the drop down i chose one it echoes out you chose blue i choose the other it says why did u choose red? Link to comment https://forums.phpfreaks.com/topic/117818-more-questions/#findComment-607668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.