Forum Moderators: coopster
$dbh=mysql_connect ("localhost", "wkpride", "password") or die ('I cannot connect to the database because: ' . mysql_error());
I was wondering if I could save this as login.php? And then when I start another page, I could just call up my login.php, rather than copy & pasting the actual code.
the questions:
1) is it possible to call scripts that are on a different page?
2) If so, is ther a specail instruction?
3) Do people do this? - or is it a bad idea?
index.php includes login.php = index.php which is the sum of both pages.
So, of course, you can reuse your code with includes in fact that is a very vital use of includes.
BUT I will not prefer this method. It is better to learn OOP and write classes. Include class in a page and then use all functions of that class using its object.
However if you want to use your connection code as an include then you can do it, this is how a lot of people do it.
BUT make sure your include file's variables do not conflict with your other page that is including the file. That might create logical bugs.