Can't Get PHP Code Working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scriptham
Forum Newbie
Posts: 4
Joined: Mon Nov 29, 2010 4:55 pm

Can't Get PHP Code Working

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can't Get PHP Code Working

Post 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?
curlybracket
Forum Commoner
Posts: 59
Joined: Mon Nov 29, 2010 2:40 pm

Re: Can't Get PHP Code Working

Post 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:

Code: Select all

if ( @mysql_query ( $sql ) )
and you will get some kind of MySQL error because your query may be wrong. That's my guess...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can't Get PHP Code Working

Post 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.
scriptham
Forum Newbie
Posts: 4
Joined: Mon Nov 29, 2010 4:55 pm

Re: Can't Get PHP Code Working

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can't Get PHP Code Working

Post by Jonah Bron »

When you run the file in your browser, what is the address in the address bar?
scriptham
Forum Newbie
Posts: 4
Joined: Mon Nov 29, 2010 4:55 pm

Re: Can't Get PHP Code Working

Post 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
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Can't Get PHP Code Working

Post 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
curlybracket
Forum Commoner
Posts: 59
Joined: Mon Nov 29, 2010 2:40 pm

Re: Can't Get PHP Code Working

Post by curlybracket »

scriptham
Forum Newbie
Posts: 4
Joined: Mon Nov 29, 2010 4:55 pm

Re: Can't Get PHP Code Working

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can't Get PHP Code Working

Post by Jonah Bron »

s992 wrote: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
http://localhost/ or http://127.0.0.1/
scriptham wrote:http://localhost/phpinfo.php
gives
Object not found!
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.
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Can't Get PHP Code Working

Post by s992 »

Jonah Bron wrote:
s992 wrote: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
http://localhost/ or http://127.0.0.1/
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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Can't Get PHP Code Working

Post by Jonah Bron »

Ah, I see. You had me wondering for a moment... :wink:
Post Reply