1

I'm learning PHP with videos of lynda.com.I created a database called widget_corp in my localhost phpmyadmin panel and I wrote these code block

    <?php
/* 1.Create a database connection */
$connection = mysql_connect("localhost", "root", "*");
if(!$connection){
die("Database connection failed: " .mysql_error());
}

/* 2. Select a database to use */
$db_select = mysql_select_db("widget_corp", $connection);
if(!$db_select)
{
die("Database selection failed: " . mysql_error());
}
?>

    <html>
    <head>
    <title> Connection To the Database </title>
    </head>
    <body>
    <?php

//3. Perform database query
$result = mysql_query("SELECT * FROM subjects",$connection);
if(!$result)
{
die("Database query failed: " .mysql_error());
}

//4. Use returned data

while($row = mysql_fetch_array($result));
{
echo $row["menu_name"]." ".$row["position"]."<br/>";
}
?>
</body>
</html>
<?php
//5. Close connection
mysql_close($connection);
?>

I always get this error type:

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.4 (Unix) PHP/5.5.3 OpenSSL/1.0.1e mod_perl/2.0.8-dev Perl/v5.16.3

How can I overcome this issue? thanks all

5
  • Whats the name of the file and whats the url u going to? Commented Nov 24, 2013 at 9:05
  • file conn.php url:localhost/xampp/conn.php Commented Nov 24, 2013 at 9:08
  • 1
    Its got to be with the location of your file. The code looks ok. try place the code directly in the www root and browse directly to localhost/conn.php Commented Nov 24, 2013 at 9:11
  • now working correctly :) thx so much Rob Commented Nov 24, 2013 at 9:17
  • For what it is worth, I agree with Rob. Try giving whoever hosts your service a call. It may be configuration as you are getting an apache error. Do you get anything if you run <?PHP phpinfo(); ?> if not then conifguration of PHP is the problem. Commented Nov 24, 2013 at 9:41

1 Answer 1

5

You made a very small mistake. You used a semicolon in while statement, so just remove it. Then it will work fine.

Use returned data:

while($row = mysql_fetch_array($result))

Not:

 while($row = mysql_fetch_array($result));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.