Make your own PHP adoptables system

Need help with the site/forum/pets? Ask questions and get help from other members here.

Re: Make your own PHP adoptables system

Postby Nick » Sun Feb 01, 2009 11:16 am

Yes, I know that, and it is working fine. You're obviously trying to use it the wrong way. If you want to display the first pet, the URL should be:

http://silverflame.comoj.com/simple.php?id=1

If you want to display the second pet the URL should be:

http://silverflame.comoj.com/simple.php?id=2

If you use this URL:

http://silverflame.comoj.com/simple.php

You will see nothing. It does not know which pet to display.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Rolly-chan » Mon Feb 02, 2009 7:20 am

Sorry to bother you again *coughs* ^^°

But I have another question (well, actually two)
1) I seem to have a problem with the second adoptables system (I copied the first one and edited it so that I could use it on other adoptables - I don't want to have them all in one big xml-file). It works fine BUT sometimes the picture doesn't display. Not always, only sometimes even though I have only ONE variation. That's kinda strange.
Why does it work sometimes and why sometimes not? ?_? I can't think of anything.

Here's the site: http://www.fluffy-adoptables.net.ms/
uhm, I forgot: it's unter bovidae ^^"

2) I want to upgrade my adoptables system. Yeah, I already activated the MySQL database and created a table with ID and date. I also know how to store the date there... and I kind of have an idea how to do this but I don't really know how. And I don't need a detailed explanation, just a cause for thought ^^

-> Can I use php-codes in the xml file? Because it's used as an objec (because of simplexml_load_file) and I'm not sure if I can use php-codes within an object.
And if I can... HOW do I modify the date from the database? I know of date("Y-m-d", strtotime(+ 1 week 2 day) ) for example. But I can't use variables in "date".

EDIT: Just found something: Can I use $var->modify("+x day") ; ?

And another question (yesh, I know I'm annoying...): When I connect to the database I have to write down my password. Is it safe to do so? o_O Can't someone else look it up then? I can't seem to find any tutorial where this is said...
User avatar
Rolly-chan
 
Posts: 2790
Joined: Tue Nov 18, 2008 8:09 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Mon Feb 02, 2009 12:08 pm

Rolly-chan wrote:1) I seem to have a problem with the second adoptables system (I copied the first one and edited it so that I could use it on other adoptables - I don't want to have them all in one big xml-file). It works fine BUT sometimes the picture doesn't display. Not always, only sometimes even though I have only ONE variation. That's kinda strange.

I cannot load your website at the moment, it just times out. I suspect that your host which you share with many other customers is overloaded at the moment.

2) I want to upgrade my adoptables system. Yeah, I already activated the MySQL database and created a table with ID and date. I also know how to store the date there... and I kind of have an idea how to do this but I don't really know how. And I don't need a detailed explanation, just a cause for thought ^^

-> Can I use php-codes in the xml file?

No, it's just XML, nothing more. Why would you want to put PHP code there?

And if I can... HOW do I modify the date from the database? I know of date("Y-m-d", strtotime(+ 1 week 2 day) ) for example. But I can't use variables in "date".

Are you trying to store the adoption date of each pet..? If you're storing a date in the database, you'll be using SQL to modify the date, nothing on the PHP end except for calling mysql_query to run the SQL. For instance, if you have a table with this structure:

Code: Select all
CREATE TABLE `pets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `adoptdate` datetime NOT NULL,
  PRIMARY KEY (`id`)
)

Then you could insert a new row with:

Code: Select all
mysql_query("INSERT INTO pets (adoptdate) VALUES (NOW())");

The ID number of the newly inserted row can then be found by calling:

Code: Select all
echo "Your new pet's ID: ".mysql_insert_id();

You can get the adoption date for a given pet by:

Code: Select all
$petid=(int) $_REQUEST['petid']; // Get the ID of the pet passed in the URL. _Make sure that it is a number_ (by casting it to int)
$result=mysql_query("SELECT adoptdate, UNIX_TIMESTAMP(adoptdate) FROM pets WHERE id=$petid");

$row=mysql_fetch_row($result);

echo "Your pet was adopted on ". $row[0];

That UNIX_TIMESTAMP(adoptdate) field gives you the adoption date in PHP's 'time' format. This allows you to format it however you like using PHP's functions, or compare it with PHP date/times. It also allows you to do this:

Code: Select all
$age=(time()-$row[1])/86400;

echo "Your pet is $age days old";

(86400 is the number of seconds in a day)

And another question (yesh, I know I'm annoying...): When I connect to the database I have to write down my password. Is it safe to do so? o_O Can't someone else look it up then? I can't seem to find any tutorial where this is said...

It's safe, since when you point your browser at your PHP file, you don't (and can't) see the code. You only see what the PHP code chooses to print out. However, if one day your webhost accidentally turns off PHP, visitors will see your code (and your password) instead of the PHP page running correctly. This would be very rare, but you can avoid this problem altogether. When you upload files, you can upload them to a folder which makes them appear at the root of your site, but on many hosts you can also upload them to the folder above that, where people cannot see (since it is above the root of your site). You could upload a file there called databasepassword.php, and put this in it:

Code: Select all
<?php $dbpassword="mypasswordhere"; ?>

Then when you need to connect to the database, you can:

Code: Select all
require("../databasepassword.php");
mysql_connect("localhost","myusername",$dbpassword);

Now your password is perfectly safe.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Rolly-chan » Wed Feb 04, 2009 7:43 am

=D thanks so much! Yeah, I wanted to store the date for each adoptable ^^

The problem with my homepage is that the free domain somehow expired o_O dunno why... I'll make myself another one somewhere else <.<

I can't upload anything into the folder above the root of my site but still, it's rather unlikely that they accidentally turn off all the PHP codes xD ^^

And I now have found a way to make them grow up after a specific amount of time *_* I'm so proud of myself for having done this almost myself ^^
They will all grow up after the same amount of days, though. But still - I don't have to remove them before they grow up ^^
User avatar
Rolly-chan
 
Posts: 2790
Joined: Tue Nov 18, 2008 8:09 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Darkkitteh99 » Tue Feb 10, 2009 1:48 pm

when is the pound open plz tell me
ImageImage Image
ImageImage Image Image
User avatar
Darkkitteh99
 
Posts: 320
Joined: Sun Feb 08, 2009 11:52 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Tue Feb 10, 2009 3:30 pm

kiks, your question does not belong here. If you're going to ask a question which is totally unrelated to the topic you're replying to, you're better off starting a new topic.

The pound opens at totally random times.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Rancor1358 » Wed Feb 11, 2009 6:19 am

Um, when I used this, when it says "Thank you for adopting this pet" and gives the the codes, the image doesn't show. And I don't know why? Help me! Please!
User avatar
Rancor1358
 
Posts: 234
Joined: Mon Nov 10, 2008 10:07 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Wed Feb 11, 2009 10:42 am

You've put URLs where you should have put filenames in the file you're using for adoptables.xml. The images must be hosted on your website. If they are in the same folder as simple.php, all you need to put is their filename, without http:// or your domain name in front.
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby qhost » Wed Feb 11, 2009 10:28 pm

Hi. I'm back again >.<

There's something that I'm - and a lot of other people are - dying to know...how to get adopter names printed on the image. I got some help on a php forum, and they recommended gd functions. I can most of it right, including what to print on the image (with a little help from members there x3), but every time the image loads the background is black and the writing is white and in the wrong corner. I've had a look at a few things under gd but I can't find anything that can help D:

Even if I did find the right codes, I probably wouldn't know where to put them XD

I used imagestring, I think, along with something else, that I can't remember x3

~Kiara
    Image-----

    she/they | adult | australia | artist | writer
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    My name is Boo & I am perpetually tired.
    Taking a break from CS for a little while!

    Spotted Tribal count: 31
    ♥︎ Click here to see the hoard! ♥︎
    -
User avatar
qhost
 
Posts: 4352
Joined: Wed Oct 01, 2008 6:36 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Wed Feb 11, 2009 11:13 pm

What code have you got so far, Kiara?
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Who is online

Users browsing this forum: No registered users and 3 guests