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
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.

Link to comment
Share on other sites

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' );

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.