Page 1 of 1
Can't Get PHP Code Working
Posted: Mon Nov 29, 2010 5:01 pm
by scriptham
Hi
I am experimenting with xampp.
I used the following code
Code: Select all
<?php
// set your information.
$host = 'localhost';
$user = 'root';
$pass = '';
$database = 'dbdoc';
// connect to the mysql database server.
$connect = @mysql_connect ( $host, $user ); //, $pass ) ;
// query string
$sql = "SELECT * FROM `tblstd` WHERE `idstd` = 1 " . mysql_real_escape_string ( $_GET['ID'] );
mysql_select_db ( $database, $connect );
if ( @mysql_query ( $sql ) )
{
echo "<p>Hit</p>";
$query = mysql_query ( $sql );
$row = mysql_fetch_assoc ( $query );
echo $row['ID'] . '<br />' . $row['std_filename'] . '<br />' . $row['std_prefix'];
}
else {
die ( mysql_error () );
}
?>
and got the following output.
Hit
"; $query = mysql_query ( $sql ); $row = mysql_fetch_assoc ( $query ); echo $row['ID'] . '
' . $row['std_filename'] . '
' . $row['std_prefix']; } else { die ( mysql_error () ); } ?>
Is it obvious to anybody where I am going wrong please.
Many thanks
scriptham
Re: Can't Get PHP Code Working
Posted: Mon Nov 29, 2010 9:14 pm
by Jonah Bron
The PHP code is not being run. Did you remember to save the file as .php, and are you opening it in your browser in
http://localhost/thefile?
Re: Can't Get PHP Code Working
Posted: Tue Nov 30, 2010 7:46 am
by curlybracket
It seems, that PHP is being run, otherwise you would see whole code from the beginning. My suspicion is that you should remove @ sign from this line:
and you will get some kind of MySQL error because your query may be wrong. That's my guess...
Re: Can't Get PHP Code Working
Posted: Tue Nov 30, 2010 10:48 am
by Jonah Bron
No, it's not visible because it's between HTML tag markers (< >). If you right-click > view source, you will see all of your code.
Re: Can't Get PHP Code Working
Posted: Tue Nov 30, 2010 3:56 pm
by scriptham
Hi
Thanks for replying
I call the php files in this way
Code: Select all
<html><body><h1>It works!</h1>
<br />
<a href="bsinsert.php">insert php</a>
<br />
<a href="bsselect.php">select php</a>
<br />
<a href="bsselectV02.php">select v02 php</a>
<br />
<a href="phpinfo.php">phpinfo.php</a>
</body></html>
Then I ran this test
Code: Select all
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(); //Also tried phpinfo(INFO_MODULES);
?>
It gives a blank screen and right click view source produced the code immediately above.
Presumably php is not being processed.
I know that xampp php code is processed though I can't unravel how they have done it.
There is a windows firewall and I have AVG antivirus free.
I have configured the windows fire wall to make exceptions in the case of mysql.exe and apache.exe
I have configured AVG to make exceptions in the case of the mysql and the apache directory.
Any ideas please.
Thanks
Scriptham
Re: Can't Get PHP Code Working
Posted: Tue Nov 30, 2010 4:42 pm
by Jonah Bron
When you run the file in your browser, what is the address in the address bar?
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 3:52 pm
by scriptham
Hi
Thanks for your reply.
The URL is
file://///Edmini/family/BS/XamppLite/xampplite/htdocs/phpinfo.php
And Edmini is a hard drive connected to my pc's via my router and RJ45.
So Xampplite is on the Edmini.
Thanks
Stewart
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 4:00 pm
by s992
You need to access it via the IP address of whatever machine you have the webhost running on.
i.e.
http://192.168.0.1/phpinfo.php
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 4:10 pm
by curlybracket
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 4:49 pm
by scriptham
Hi
thanks for you replies.
http://localhost/phpinfo.php
gives
Object not found!
http://192.168.0.1/phpinfo.php
gives
Connection timed out, server taking too long to respond.
I guess that this means I will have to run Xampp on C:/
What I haven't explained is that I want to run a database and webserver from a CDRom effectively giving me simple interactive web via SELECT queries. It is partly for work and as we are not allowed USB memory sticks the CDRom seems the only solution. I will also need to encrypt the CDRom at some stage but that is in the future.
Any tips greatly appreciated.
Scriptham
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 4:58 pm
by Jonah Bron
http://localhost/ or
http://127.0.0.1/
I think that means you didn't set your DocumentRoot correctly. Did you set it to your CD-ROM? I see no reason why it couldn't work from there, as long as it doesn't have to change any files.
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 5:27 pm
by s992
It sounded to me like it was not running on his local machine but rather a machine on his network, but after re-reading his post I can see that he was referencing an external hard drive or something.
Re: Can't Get PHP Code Working
Posted: Wed Dec 01, 2010 6:12 pm
by Jonah Bron
Ah, I see. You had me wondering for a moment...
