PDA

View Full Version : php question +rep



Trigs
31-07-2010, 08:52 PM
I have 3 files. a.php, b.php, and c.php. In each file I have require 'lol.php'. In lol.php I want to create a variable with the filename (either a.php, b.php, or c.php, not lol.php). Would I use $_SERVER['PHP_SELF'] or $_SERVER['SCRIPT_NAME'] or what? Or is there no predefined way variable for this?

+rep to those who help.

Homosexual
31-07-2010, 08:57 PM
You can use any, although there are differences. Read up on them from here: http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm :)

MattFr
31-07-2010, 09:45 PM
basename(__FILE__);

Trigs
31-07-2010, 09:49 PM
You can use any, although there are differences. Read up on them from here: http://php.about.com/od/learnphp/qt/_SERVER_PHP.htm :)

Thanks it worked.


basename(__FILE__);
Didn't work. It showed lol.php instead of 1/2/3.php

Also having another problem. I'm getting


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

The code:



$file = htmlspecialchars($_SERVER['SCRIPT_NAME']);
$query = mysql_query(" SELECT * FROM tablename WHERE file = '$file' ");
$count = mysql_num_rows($query);


Database connection was done before the code. I can verify that the database and tables exist. Can't figure it out though.

Homosexual
31-07-2010, 09:59 PM
Fazon,

Show me what happens when you use this code instead:



$file = htmlspecialchars($_SERVER['SCRIPT_NAME']);
$query = mysql_query(" SELECT * FROM tablename WHERE file = '$file' ") or die(mysql_error());
$count = mysql_num_rows($query);


:)

Trigs
31-07-2010, 10:02 PM
Nevermind, figured it out. I didn't create the table/user. The guy who did doesn't know php/sql so he didn't give the mysql user any permissions.

Thanks for your help though!

Homosexual
31-07-2010, 10:03 PM
It's alright, hit me up a PM if you get any other troubles! :)

Trigs
31-07-2010, 10:06 PM
Yeah thanks, haven't coded a system in about a year.

Homosexual
31-07-2010, 10:09 PM
PHP isn't my strong point, but I help whenever I can (:

Want to hide these adverts? Register an account for free!