Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2012, 01:52 AM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,219
SilverDragonTears is on a distinguished road
Default Curses... Unique naming

When a user names their pet and the name is already taken, how can I show that? I have it set where names are unique.

Code:
		// We are renaming an adoptable

			// Now we see if the adoptable actually exists...

			$stmt = $adopts->query("SELECT * FROM {$prefix}owned_adoptables WHERE owner='{$loggedinname}' and aid='{$id}'");
			$row = $stmt->fetchObject();

			if($row->aid == $id)
			{
				$image = getcurrentimage($id);

					if($more == "")
					{

						$article_title = "Rename {$row->name}";
						$article_content = "<img src='{$image}'><br />{$lang_rename}{$row->name}{$lang_rename2}<br />
											<form name='form1' method='get' action='myadopts.php'>
												<p>Adoptable Name: 
													<input name='more' type='text' id='more'>
													<input name='id' type='hidden' id='id' value='{$id}'>
													<input name='act' type='hidden' id='act' value='rename'>
												</p>
												<p>
													<input type='submit' name='Submit' value='Rename Adoptable'>
												</p>
											</form>";
					}

					else
					{
						// We are renaming the adoptable
__________________

Check out SilvaTales
Reply With Quote
  #2  
Old 03-27-2012, 02:53 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 327,492
Hall of Famer is on a distinguished road
Default

Well it isnt really difficult, just find this part in your script:

PHP Code:
             else{
                        
// We are renaming the adoptable

                        // The adoptable exists, so now we can rename it...
                        
$adopts->query("UPDATE {$prefix}owned_adoptables SET name='{$more}' WHERE aid='{$id}' and owner='{$loggedinname}'");

                        
$article_title $lang_rename_success_title;
                        
$article_content "<img src='{$image}'><br />{$lang_rename_success}{$more}
                                            You can now manage 
{$more} on the <a href='myadopts.php?act=manage&id={$id}'>My Adopts</a> page";
                    } 
And replace with:

PHP Code:
             else{
                    
$stmt $adopts->query("SELECT * FROM {$prefix}owned_adoptables WHERE name='{$more}' and aid='{$id}'");
                    
$row $stmt->fetchObject();
                    if(!
is_object($row)){ 
                       
// The name has not yet been used, we are good to go!
                        
$adopts->query("UPDATE  {$prefix}owned_adoptables SET name='{$more}' WHERE aid='{$id}' and  owner='{$loggedinname}'");

                        
$article_title $lang_rename_success_title;
                        
$article_content "<img src='{$image}'><br />{$lang_rename_success}{$more}
                                            You can now manage 
{$more}  on the <a href='myadopts.php?act=manage&id={$id}'>My  Adopts</a> page";
                     }
                     else{
                      
// The name is being used by someone else, so display an error message...
                        
$article_title "An error has occurred";
                        
$article_content "It appears that the name {$more} is taken already.";
                     }
                  } 
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #3  
Old 03-27-2012, 03:13 AM
fadillzzz fadillzzz is offline
Dev Staff
 
Join Date: Jan 2010
Posts: 501
Gender: Male
Credits: 32,506
fadillzzz is an unknown quantity at this point
Default

Assuming you have a unique index on the name field, this can be achieved without any additional query.

PHP Code:
$stmt $adopts->query('...');
if ( ! 
$stmt)
{
    
// failed, the name is already in use
}
else
{
    
// successfully renamed

I think this would be a much better solution, because not only that you keep the MySQL from choking, but you also keep your code succinct.

Last edited by fadillzzz; 03-27-2012 at 03:15 AM.
Reply With Quote
  #4  
Old 03-27-2012, 03:16 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 327,492
Hall of Famer is on a distinguished road
Default

Good idea Fadillzzz, $stmt should return false if the query fails. This should significantly reduce the memory consumption for cases that the script merely checks if a row exists. Also it is better just to select the field name from the database instead of using '*', I just showed her an example of how to do this kind of trick though.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #5  
Old 03-27-2012, 04:09 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,219
SilverDragonTears is on a distinguished road
Default

Hof yours didn't work :/
__________________

Check out SilvaTales
Reply With Quote
  #6  
Old 03-27-2012, 04:47 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,219
SilverDragonTears is on a distinguished road
Default

Pardon me for being ignorant... where do I put this and what do I put in the ('...')

Quote:
Originally Posted by fadillzzz View Post
Assuming you have a unique index on the name field, this can be achieved without any additional query.

PHP Code:
$stmt $adopts->query('...');
if ( ! 
$stmt)
{
    
// failed, the name is already in use
}
else
{
    
// successfully renamed

I think this would be a much better solution, because not only that you keep the MySQL from choking, but you also keep your code succinct.
__________________

Check out SilvaTales
Reply With Quote
  #7  
Old 03-27-2012, 04:48 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 327,492
Hall of Famer is on a distinguished road
Default

Oh my I must suffered from a lack of sleep then, lol. Remove this part from the very first line and it should work:

PHP Code:
 and aid='{$id}' 
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #8  
Old 03-27-2012, 06:01 PM
SilverDragonTears's Avatar
SilverDragonTears SilverDragonTears is offline
I am your Nemesis.
 
Join Date: Jun 2011
Posts: 1,113
Gender: Female
Credits: 81,219
SilverDragonTears is on a distinguished road
Default

What would I do without you Hof?
__________________

Check out SilvaTales
Reply With Quote
  #9  
Old 03-27-2012, 06:04 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 327,492
Hall of Famer is on a distinguished road
Default

lol you flattered me. And I apologize for giving you the wrong codes in the first place. XD
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mys v1.3.4 Know Gender of New Pets Before Naming Kyttias Mys v1.3.x Mods 4 08-04-2018 01:13 AM
Show Gender while Naming Pet & Name Promo Code Pets Kyttias Questions and Supports 5 07-11-2014 02:12 PM
Naming and Changing Help whispwill Suggestions and Feature Requests 10 08-29-2009 02:58 PM


All times are GMT -5. The time now is 01:57 PM.

Currently Active Users: 432 (0 members and 432 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636