homepage Welcome to WebmasterWorld Guest from 54.161.155.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
If (Username exists){echo 1} else {echo 2}
Thats basically it but I cant get it to work right.
dkin




msg:1281280
 7:44 pm on Jan 5, 2005 (gmt 0)

Ok the problem Im haveing as you see above is I have a gaming site, I want someone to create an account and when they initially log in there should be a form that says create a character, if they dont fill it in and log out then the next time they log in it will still be there, if they do fill it out I want there user info to show, the problem that I am having is that when they create a charachter the character form stays on tyhe screen, I dont want it to do that.

Thank you for any help.

This is my code

##Connect to Character Database
$cresult = mysql_query("SELECT * FROM user_char", $link) or die ("query 1: " . mysql_error());
$crow = mysql_fetch_array($cresult) or die ("query 2: " . mysql_error());


##Beginning table inside inner Table, User information
echo '<table border="1" cellpadding="5" cellspacing="0">'
. '<tr><th colspan="2" align="width">Account Information</th></tr>'
. '<tr><td width="100">Username</td><td width="200">'.$urow[username].'</td></tr>'
. '<tr><td width="100">Email</td><td width="200"><form action="'.$php_self.'" method="post"><input type="text" name="email" value="'.$urow[email].'" /><input type="submit" name="updateemail" value="Update Email"/></form></td></tr>'
. '</table>';
##End user information table

echo '</td><td>';

if ($username == $crow[username]){
##Begin 2nd table inside inner table, Character information
echo '<table border="1" cellpadding="5" cellspacing="0">'
. '<tr><th colspan="2" align="center">Character Information</th></tr>'
. '<tr><td width="100">Race</td><td width="200">'.$crow[race].'</td></tr>'
. '<tr><td width="100">Rank</td><td width="200">'.$crow[rank].'</td></tr>'
. '<tr><td width="100">Gold</td><td width="200">'.$crow[gold].'</td></tr>'
. '<tr><td width="100">Name</td><td width="200">'.$crow[name].'</td></tr>'
. '<tr><td width="100">Weapon</td><td width="200">'.$crow[weapon].'</td></tr>'
. '<tr><td width="100">Helmet</td><td width="200">'.$crow[helmet].'</td></tr>'
. '<tr><td width="100">Armor</td><td width="200">'.$crow[armor].'</td></tr>'
. '<tr><td width="100">Bracers</td><td width="200">'.$crow[bracers].'</td></tr>'
. '<tr><td width="100">Gloves</td><td width="200">'.$crow[gloves].'</td></tr>'
. '<tr><td width="100">Greaves</td><td width="200">'.$crow[greaves].'</td></tr>'
. '<tr><td width="100">Boots</td><td width="200">'.$crow[boots].'</td></tr>'
. '</table>';
##End Character Information table
}
else
{
##Echo the Create a Character form
echo '<table border="1" cellspacing="0" cellpadding="4"><tr>'
. '<th colspan="2">Create A Character</th></tr>'
. '<tr><td>Charcter Name</td><td><form action="account.php" method="post"<input type="text" name="charname"/></td></tr>'
. '<tr><td>Race</td><td><select name="charrace"><option value="Human">Human<option value="Orc">Orc</select></td></tr>'
. '<tr><td colspan="2"><input type="submit" name="createchar" value="Create"/></form></td></tr></table>';
##End the create a character form
}

 

mavherick




msg:1281281
 8:02 pm on Jan 5, 2005 (gmt 0)

I'm not too sure where your variable $username is coming from, but assuming it's previously set, I'd try this for a starter:

$cresult = mysql_query("SELECT * FROM user_char WHERE username='".$username."'", $link) or die ("query 1: " . mysql_error());

Adding the WHERE clause makes sure you only pickup the character info belonging to that username. It might cause problem down the line if there's no returned result, like someone without a character yet. But I'd start with that.

Hope that helps.

mavherick

dkin




msg:1281282
 8:10 pm on Jan 5, 2005 (gmt 0)

I tried that but it cannot pull anything from that table because that is where the user characters are stored and each user can only have one so it returns an error, because at this point they do not have a character.

mavherick




msg:1281283
 8:18 pm on Jan 5, 2005 (gmt 0)

In that case, simply move the second line of code ($crow = mysql_fetch_array($cresult) or die ("query 2: " . mysql_error());) inside your "if" which you should modify like this to test if there's any result returned from your querry:

if (mysql_num_rows($cresult) > 0) {
$crow = mysql_fetch_array($cresult) or die ("query 2: " . mysql_error());
....

mavherick

dkin




msg:1281284
 8:28 pm on Jan 5, 2005 (gmt 0)

If I move the

$crow = mysql_fetch_array($cresult)

into the if it will not display the correct results, unless I can do something like

if ($crow = mysql_fetch_array($cresult) == $username)
{
}

shed any more light on this?

mavherick




msg:1281285
 8:39 pm on Jan 5, 2005 (gmt 0)

Sorry, I forgot to mention to also use the query as I mentionned in message #2 which takes care of fetching the user's character. The modified "if" will then check if the user actually has a character, if yes, it should display the char info, if not, the form.

mavherick

dkin




msg:1281286
 9:50 pm on Jan 5, 2005 (gmt 0)

Works great, thanks alot.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved