Jump to content

[SOLVED] What is wrong with my code?


andrewgarn

Recommended Posts

I created a simple php file which should connect to mySQL and list the contents of a table and echo them onto the page.

 

<html>
<head>
<title>Show database containing Users</title>
</head>
<body>
<?php


$conn = @mysql_connect( 'localhost', 'root', '' )
or die( 'Could not connect to MySQL' );


$rs = @mysql_connect_db( 'singer', $conn )
or die( 'Could not select database' );


$sql = 'SELECT * FROM `owner`'
or die('There is a problem with the query' );


$rs = mysql_query( $sql, $conn )
or die('Problem');


while( $row = mysql_fetch_array( $rs ) )
{
echo( 'Name: ' . $row['name'] );
echo( 'Address: ' . $row['house'] );
echo( ', ' . $row['street'] );
echo( ', ' . $row['town'] );
echo( ', ' . $row['county'] );
echo( ', ' . $row['country'] );
echo( ', ' . $row['postcode'] );
echo( 'Email: ' . $row['email'] );
echo( 'Phone Number: ' . $row['phone'] );
echo( 'Mobile Number: ' . $row['mobile'] );
}
?>
<p>Test</p>
</body>
</html>

 

When i run the page I can see nothing, and when I view the source code i see this:

 

<html>
<head>
<title>Show database containing Users</title>
</head>
<body>

 

Any help you can give me would be appreciated. I am running an Apache server with mySQL, both installed using a program called XAMPP

 

Thanks

Andrew

Link to comment
https://forums.phpfreaks.com/topic/94744-solved-what-is-wrong-with-my-code/
Share on other sites

I'm not the world's greatest with syntax, but try replacing

 

echo( 'Name: ' . $row['name'] );
echo( 'Address: ' . $row['house'] );
echo( ', ' . $row['street'] );
echo( ', ' . $row['town'] );
echo( ', ' . $row['county'] );
echo( ', ' . $row['country'] );
echo( ', ' . $row['postcode'] );
echo( 'Email: ' . $row['email'] );
echo( 'Phone Number: ' . $row['phone'] );
echo( 'Mobile Number: ' . $row['mobile'] );

 

with

 

echo "Name: $row['name']";
echo "Address: $row['house']";
echo "$row['street']";
echo "$row['town']";
echo "$row['county']";
echo "$row['country']";
echo "$row['postcode']";
echo "Email: ' . $row['email'] );
echo "Phone Number: ' . $row['phone'] );
echo "Mobile Number: $row['mobile']";

 

If it works, you can play with it to format it how you want, not sure this is the problem 100% but see if it works.

aebstract - your code can't be right surely? as it mixes up the text with variable names inside quotations? Anyway i tried it, it didnt work

 

Revraz - i removed the @before the first two commands and got this:

 

Fatal error: Call to undefined function mysql_connect_db() in C:\Server\XAMPP\htdocs\owner.php on line 13

 

Line 13 and 14:

 

$rs = mysql_connect_db( 'singer', $conn )

or die( 'Could not select database' );

Thanks for that, read the sticky.

 

found a php.ini file in C:\Server\XAMPP\php

 

As far as i can see the the things in the sticky were already done?

 

extension_dir = "C:\Server\XAMPP\php\ext\"

 

extension=php_mysql.dll (no semi colon at the start)

 

 

Any other suggestions?

 

here is a link to my php.ini file

http://idire.no-ip.org/php.ini.txt

it looks to be missing a few things in the config, if its not your server contact your admin on fixing this

 

Its mine, however I just noticed its loaded a different php file to the one I edited.

 

I will edit the php file in C:\windows and see if it helps?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.