Re:Applying PHP code using DirectPHP to Joomla Site (1 viewing) (1) Guest
Favoured: 0
|
|
|
TOPIC: Re:Applying PHP code using DirectPHP to Joomla Site
|
|
|
|
Applying PHP code using DirectPHP to Joomla Site 10 Months ago
|
Karma: 0
|
Dear community...
I really hope someone can help me. I do web work for a club and we use Joomla v2.5.4.
I've installed the appropriate version of DirectPHP and I have activated the component and I can defiantly input PHP code as it generates errors accordingly, that seem relevant to php code.
The problem I am having is, on our old site, we had php files which to me appear to more like html code and then a specific php tags with 1 line of php code, end php tag... This line of php code on the old site would then operate correctly, link into a dedicated database of names and addresses etc and display that information based on a unique 'college' id number. Thus the college id number is different for each 'college' php file.
I had some problems with getting a database not found error, co I've added that into the directorprefill2.php file and so I get a 'normal' php error.
So the code I'm using in Joomla, in the Category section is this:
| Code: | <?php
mysql_connect ("db", "dbname", "dbpassword");
mysql_select_db('dbname');
$thiscollegeid = 74; include("/home/sfa/acad.sfi.org/staff/directorprefill2.php");
?> |
There will be ordinary text after this, but I just need the php code to work first. I've removed the real database name and password for obvious reasons.
The error I get on the front end of the website is as follows:
Parse error: syntax error, unexpected '<' in /home/sfa/acad.sfi.org/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 1
No the obvious check here to me is the DirectPHP.php file, line 1... but line 1 is the opening php tag...
I've been at this for far too long and I desperately just want it to work and would gratefully accept any help to work towards getting it to work.
JT
|
|
|
|
|
|
|
Last Edit: 2012/08/18 18:11 By sfa_academy.
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 1680
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 10 Months ago
|
Karma: 27
|
|
Hi,
Please do the following 2 things and let me know what you see on the screen:
1) You have only 4 lines above. Can you delete the 4th line (i.e. the one containing the include). Now reload the page and let me know what error messages you see on the screen.
2) Put all the 4 lines into a standalone .php file. Then use DirectPHP to include that .php file. Now reload the page. Let me know what is the error messages that you see on the screen.
Regards,
/kksou
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 3 Weeks ago
|
Karma: 0
|
Hi kksou
1) - Error is still
Parse error: syntax error, unexpected '<' in /home/sfa/acad.sfi.org/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 1
2) I've put the entire code into a file called test.php and I'm using the following in Joomla to 'include' it...
| Code: | <?php
include("/home/sfa/acad.sfi.org/staff/test.php");
?> |
I am still getting the same error
Parse error: syntax error, unexpected '<' in /home/sfa/acad.sfi.org/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 1
JT
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 1680
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 3 Weeks ago
|
Karma: 27
|
|
Hi,
Can you replace the above include() with simply
echo('test123');
Please let me now if you still get the same error message, or you see 'test123' on the screen.
Regards,
/kksou
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 3 Weeks ago
|
Karma: 0
|
|
Hi kksou
The category page I was using I think might be corrupt... so I've tried a fresh new one and used the echo test123 as you instructed in your last message and I confirm I see test123 on the screen. I've even attempted to try different words etc, to just confirm it is defiantly reporting correctly and it is...
What next?
JT
PS - I appreciate the assistance and I really hope we can sort this out so I can get what I am trying to do to work.
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 1680
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 2 Weeks ago
|
Karma: 27
|
|
Hi,
Sorry for the late reply.
If you see "test123" on the screen, it means DirectPHP is working fine.
Then it boils down to the "directorprefill2.php" you are trying to include.
I believe there are many lines in directorprefill2.php. You have to have a bit of patience to find out which is the line within directorprefill2.php that is giving the problem.
So start, say the first 10 lines of directorprefill2.php. Include the file using DirectPHP and see if it works. For testing purpose, always include one more line "echo 'test123<br>';" as the last line of directorprefill2.php so that you know the included file runs ok if you see 'test123' on the screen.
If the first 10 lines work, then include the following 10 lines. Do this one by one and you will find the line that is causing the problem.
When you find the line, let me know. And we'll see how we can resolve the problem.
Regards,
/kksou
|
|
|
|
|
|
|
Last Edit: 2012/09/02 13:57 By kksou.
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 2 Weeks ago
|
Karma: 0
|
Hi kksou
OK I've as suggested and I believe I have located the problem line.
I went one step further also and commented out the line to see what would happen... besides the Test 123 appearing (as you indicated it should), it also displayed the generic text associated with the directorprefill2.php file which is a great sign. I've then tried adding in the $thiscollegeid = 74 to the Joomla page php code i.e. $thiscollegeid = 74; include("/home/sfa/acad.sfi.org/staff/directorprefill.php"); but it does not change the result on the page it just stays at the generic information. the number should make it go to the database being called to find college id 74 and then slot in the director info listed in the database onto the page in place of the generic information currently being displayed.
i.e. it currently shows:
This curriculum is closed
at the current time,
Director
it should display:
Joe Bloggs,
Director joe@bloggs.org
123 Apple Street
Some Country 123456
The problem line (I believe from my tests) is Line 15 which is | Code: | $pow = runQueryArray('Get specific article', $query); |
Here is the code for the full directorprefill2.php file so you can see the rest of the code as well. I've removed the database and password info for obvious reasons.
| Code: | <?php
require_once($_SERVER['DOCUMENT_ROOT']."/onlineacad/needdirpath.php");
//require_once($basedir."/onlineacad/dbinfo.php");
mysql_connect ("dbname", "db", "dbpassword");
mysql_select_db('db_1');
//$thiscollegeid = $_POST['thiscollegeid'];
$lastcatshown = 0;
$query = "Select directorname, email, address1, address2 from colleges
where colleges.id='$thiscollegeid' and status=1";
$pow = runQueryArray('Get specific article', $query);
if(!$pow[0])
{
$directorname = 'This curriculum is closed<BR>at the current time';
$directoraddress1 = '';
$directoremail = '';
$directoraddress2 = '';
}
else
{
$directorname = $pow[0];
$directoremail = $pow[1];
$directoraddress1 = $pow[2];
$directoraddress2 = $pow[3];
}
$content .= "<span class=\"bodytext\"><b>".$directorname.",</b></span><br><span class=\"bodytext\"><b><i>Director</i><br><span class=\"bodytext\"><a href=\"mailto:".$directoremail."\">".$directoremail."</a><br></span>".$directoraddress1."<br>".$directoraddress2."</b></p></span>";
echo $content;
echo('Test of New College Page_Alpha');
?> |
Thanks
JT
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 1 Week ago
|
Karma: 0
|
Hi kksou
So do you mean that I need to do add the following code at the end of the code in the directorprefill2.php file before the echo of our test message?
| Code: |
mysql_connect ("dbname", "db", "dbpassword");
mysql_select_db('j17_db_1');
|
The joomla database is the same database as the one used for the director information, with the exception that the Joomla database has a prefix of j17_
Is the above code correct? I have put it in anyway and un commented out line 15 and I'm getting the original line 15 error... I fI leave line 15 commented out there is no change.
Cheers
JT
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
kksou (Admin)
Admin
Posts: 1680
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months, 1 Week ago
|
Karma: 27
|
|
Hi JT,
You mentioned that "it also displayed the generic text associated with the directorprefill2.php".
So what are those "generic text"? Can you tell me what you see on the screen?
Also, you have included one more file
require_once($_SERVER['DOCUMENT_ROOT']."/onlineacad/needdirpath.php");
The error could also be from that file.
In any case
1) For your joomla system, it runs on its own database.
2) You have switched the database using
mysql_connect ("dbname", "db", "dbpassword");
3) Because of this, at the end of your "directorprefill.php" (if it works properly), you have to switch back to the joomla database
mysql_connect ("joomla_dbname", "joomla_db", "joomla_dbpassword"); #this is the database, username and password that you have used when you set up the joomla db
If you do not want to do so, try importing those additional tables into your joomla db. Then you do not need to switch between the two databases.
Regards,
/kksou
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
Re:Applying PHP code using DirectPHP to Joomla Site 9 Months ago
|
Karma: 0
|
Dear kksou
The ‘default’ text the directorprefill2.php uses is:
This curriculum is closed
at the current time,
Director
However in Joomla, the php code tells it which College ID it needs to find in the database and pull the information.
For example in Joomla I have
| Code: |
<?php
$thiscollegeid = 74; include("/home/sfa/acad.sfi.org/staff/directorprefill2.php");
?>
|
The directorprefill2.php should then tell it what to do… at least that’s how it works in the old website without any problems.
My Joomla installation uses the same database as where this other information is.. the difference is Joomla uses a j17_ prefix to the database. I’ve added a mysql_select_db line with j17_sfa, so that should reconnect the Joomla database.
Either way when I uncomment out line 15 I get the error. Do you think line 15 may be connected to this other included file?
This other file you indicated has the following code:
| Code: |
<?php /**/ ?><?php
//$baseDir=$DOCUMENT_ROOT."/onlineacad"; //<-- Removed 2010/06/03, JHH
$basedir = $_SERVER['DOCUMENT_ROOT'];
|
I don’t see anything in that file that would cause a problem.
Is there nothing on line 15 that could be the problem, or is missing etc?
JT
|
|
|
|
|
|
|
The administrator has disabled public write access.
|
|
|
|
|