Page 1 of 1

Create values and using databases and tables correctly?

Posted: Thu Aug 10, 2006 12:52 am
by ekosoftco
ok, ran into another problem.
I have the check and i have it where people can setup guilds.
i use the header refer to /page.php?action=registered
after everything is set up and the guild is sent into the guild database,
but what i need is to be able to set the field guild in the user database to the value of 1, so when the person goes back to guild create they dont see another create guild form, but instead get refered to the guildcp itself.
i have all the checks and everything set up and working, i just cant seem to code it right so that it sets the guild value in the user table database ( a whole different databse for the guilds).

i was also wondering if it would be better for me to use the same database for guilds with a different table other than the user table, please let me know. Right now i have the user database with a guild field for true or false, a guild database which holds each guilds id, name, public info, and another table in the guild database where it holds the members info for each guild. i was also wondering if its possible to use 2 different tables like that, or if i could use one table somehow. i need to be able to hold the guilds info and the members and thier ranks and info for the guild. i cant seem to come up with a logical way to do this either, besides making 2 tables and making them coincide(spelt right?). should i just add more fields to the user table and then somehow attach it to work with the guild database?

Posted: Fri Aug 11, 2006 8:15 pm
by ekosoftco
anyone please?

Posted: Sun Aug 13, 2006 1:33 am
by ekosoftco
:x

Posted: Sun Aug 13, 2006 3:34 am
by RobertGonzalez
Before we get to far into this, post some code and point us to where the code is not working.

Posted: Sun Aug 13, 2006 10:15 am
by ekosoftco
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


please forgive me, as im not quite sure as to what proper bbcode posting is.

Code: Select all

<?php
if (isset($_SESSION['Guild'])) 
{ 
    // Ok, the session var 'Paid is set 
    if ($_SESSION['Guild']) 
    { 
echo "<center><b>Welcome Guild</b><br>";
    } 
    else 
    { 


//show the form
require('configg.php');
echo "<center><b>Create a Guild</b><br>
You meet all the requirements to create a guild. Each account can create one guild. You can then
manage your guild from the guildcp.";
echo "<form method=post action=?action=check><table><tr><td><font size=2>
<tr><td><font size=2>Guild Tag:</td><td><input type=text name=Gtag></td></tr>
<tr><td><font size=2>Confirm Guild Tag:</td><td><input type=text name=CGtag></td></tr>
<tr><td><font size=2>Full Guild Name:</td><td><input type=text name=Fgname></td></tr>
<tr><td></td><td><input type=submit value=Submit></td></tr></table></form></font>";
//see if action=check
if($_GET['action'] == 'check')
{
   //check if everything is filled in
   if($_POST['Gtag'] == '' || $_POST['CGtag'] == '' || $_POST['Fgname'] == '')
   {
      //if everything is not filled in than print out "please fill in all the field"
	  echo error("blank");
	  exit;
   }
   else
   {
      //check if the tags match
	  if($_POST['Gtag'] !== $_POST['CGtag'])
	     {
		 //if they dont match than print out "passwords dont match"
		 echo error("tags");
		 exit;
		 }
      else
	     {
		 //if they match, see if the user exists
         $result = mysql_query("SELECT * FROM guildphp
         WHERE Gtag='{$_POST['Gtag']}'") or die(mysql_error()); 
         $row = mysql_fetch_array( $result );
		 //if row uname equals blank than create the user
         if($row['Gtag'] == '')
		    {
		    //create the user
			//remove any html tags
			$_Gtag = str_replace("<", "", $_POST['Gtag']);
			$_Fgname = str_replace("<", "", $_POST['Fgname']);
            mysql_query("INSERT INTO guildphp 
            (Gtag, Fgname) VALUES('$_Gtag', '$_Fgname') ") 
            or die(mysql_error());
			//redirect to login.php?action=registered		
header("Location: guildcp.php?action=registered");
		    }
		 else
		    {
			echo error("tagused");
			}	
            }
	}
}
//function error
function error($error)
{
   //if error is equal to blank than write "fill in all the fields"
   if($error == 'blank')
      {
      echo "<b>Please fill in all the fields</b>";
      }
   //if error is equal to password than write "the passwords dont match
   if($error == 'tags')
      {
      echo "<b>The passwords do not match</b>";
      }
   //if error is equal to user than write "the username is already registered"
   if($error == 'tagsused')
      {
      echo "<b>The username is already registered</b>";
      }
}


    } 
} 
else 
{ 
    // Session var 'guild' is not set, 
    // Redirect to A FULL URL AS PER THE MANUAL 
    header("Location: http://cyril.ulmb.com/start.php"); 
    exit; 
}
?>

i actually want to use headers to put to createguild.php if the guild=1
i took out what i had, because it didnt work at all, and its been about 3 days so i forgot exactly what i had. it was right before the action=?registered header but after action registered set, i wanted to send a query update so the user field guilds is =1, so they cannot try to set another guild, and only have 1.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Aug 13, 2006 10:50 am
by RobertGonzalez
Couple of issues you are going to have right off the top...

1. Your form has absolutely no double quotes around your tag attributes (name=name should be name="name"). This could have a dramatic effect on the performance of your script.

2. You are checking isset(GET['action']) inside the section of your script that shows the form. This is absolutely redundant because the value of your action attribute is set in the markup. This will always return true. Is that is the case, remove the conditional and just run the code.

3. You are using relative URLs in the header() function. The PHP manual says to use full URLs.

4. Your replacement of HTML tags is only replacing opening and closing brackets. Is this what you want?

Maybe what you could do is write out a brief logic structure, the code to that logic structure. Something along the lines of:

Code: Select all

if (session is set)
{
    let the user in
    if (other data is true)
    {
        Do this
    }
    else
    {
        Do this if the other data is false
    }
}
else
{
    the user is not authorized so redirect
}
Then, while looking at your desired logical flow, write your code and see how it comes out.

Posted: Sun Aug 13, 2006 12:24 pm
by ekosoftco
ok, i got that fixed, but now my big problem was

i use the header refer to /page.php?action=registered
after everything is set up and the guild is sent into the guild database,
but what i need is to be able to set the field guild in the user database to the value of 1, so when the person goes back to guild create they dont see another create guild form, but instead get refered to the guildcp itself.
i just seem to code it right so that it sets the guild value in the user table database ( a whole different databse for the guilds).

i was also wondering if it would be better for me to use the same database for guilds with a different table other than the user table, please let me know. Right now i have the user database with a guild field for true or false, a guild database which holds each guilds id, name, public info, and another table in the guild database where it holds the members info for each guild. i was also wondering if its possible to use 2 different tables like that, or if i could use one table somehow. i need to be able to hold the guilds info and the members and thier ranks and info for the guild. i cant seem to come up with a logical way to do this either, besides making 2 tables and making them coincide(spelt right?). should i just add more fields to the user table and then somehow attach it to work with the guild database?

Posted: Sun Aug 13, 2006 5:11 pm
by RobertGonzalez