Hi Carlos,
I hope to understand you well. you didn't mention whether moodle shows you the error message or your other php application shows it.
Anyway, you can access the current logged in user by the $USER global object (for example his username is $USER->username).
My first suggestion would be to upgrade to the latest Moodle version. 1.5 is so old now, that it makes it difficult to get help from developers.
As for your problem, you might try adding:
require_once("../../config.php");
to the top of your file (change the path if necessary)
The require_once call is a PHP fucntion. It should be inside php tags. If it's outside PHP tags it will be shown as text. That's why the code is shown, instead of executed. Don't include the HTML header. You should use PHP to send the header. This discussion shows a nice example of a basic Moodle page. It prints the header, checks if the user is loggedin, and provides you with all the global variables you need, like $USER to know which user is logged in.
require_once("../config.php");
require_login();
print_header( 'My Page Title',
'My Page Title',
'My Page Title');
print_simple_box_start("center", "", "", 5, "generalbox", "mypage");
print("<p>Hello, world!</p>");
print_simple_box_end("center");
print_footer();
only that code, i erase all the other html stuff, but I still obtain a page with the text , look the pic attachment and you would see what i obtain.
Hi Carlos,
In order to link your other php file, here is a suggestion when you don't want to modify moodle files:
Choose "Insert a label" from "Add a resource" combo box and then write the text of your link. you may use html tags to put a link instead of a simple label.
Cheers
If I write the link like you said Shamim, i cannot recieve variables like user name and other that I need.,...

just write require_once("path_to_your_moodle_root_folder/config.php")
and then you can access whatever you need.
Here is an example:
<?php
require_once('../config.php');
require_login();
echo 'Your name is ' . $USER->firstname;
?>
From looking at the screenshot, I gather you are still putting your php files inside the moodle data directory. (The location bar shows file.php/2/ before your PHP file. The file.php script doesn't execute PHP code as a security measure. Just put your file somewhere inside your moodle application directory (where the other PHP files reside), NOT the moodle data directory.
Inside the screenshot I also see a lot of direct SQL queries. Please make sure that what you insert into the database ($idpregunta) is completely secure and not vulnerable to SQL injection. It would be better (though I understand you may not have the time) to use Moodle database calls instead, they provide some basic security. It wouldn't be the first time a Moodle installation is made insecure by third party code added to it.
Good luck with your presentation.