PHP error code

Closed
Hudaibia Posts 1 Registration date Thursday August 23, 2012 Status Member Last seen August 23, 2012 - Aug 23, 2012 at 07:11 AM
shoaibista Posts 8 Registration date Friday May 24, 2013 Status Member Last seen May 27, 2013 - May 24, 2013 at 11:12 AM
<?php
include '../../MySQl/Includes/Connection.php';
$query="SELECT *FROM bridal_info WHERE ID=1";
$result=mysql_query($query) or die (mysql_error());
while($person=mysql_fetch_array($result))
{
echo "<h3>"."Colour :" ." ". $person['Colour']."</h3>";
echo "<h3>"."Fabric :"." " .$person['Fabric']."</h3>";
echo "<h3>"."Price :". " ".$person['Price']."</h3>";
}
?>
This is my code and Error in my webpage is :No database is selected.
Please solve this problem.

2 responses

Bionik Posts 4234 Registration date Thursday August 19, 2010 Status Moderator Last seen August 3, 2016
Sep 3, 2012 at 05:15 AM
Hello,

You have problem with the include file named Connection.php. Verify that the path of the file is correct or directly connect to your mysql database before your sql statement.

You can use PDO to do it, here is the code;

  <?php 
  
  try {
          $db = new PDO('mysql:host=localhost;dbname=your_database_name', 'your_username',  'your_password');
   }
   
   catch(PDOExeption $e) {
   die('Error connecting to the database' .$e->getMessage());
   }
   
   $query="SELECT * FROM bridal_info WHERE ID=1"; 
   $result= $db->query($query) or die (print_r($db->errorInfo())); 
   
       while($person = $result->fetch()) 
       { 
         echo "<h3>"."Colour :" ." ". $person['Colour']."</h3>"; 
         echo "<h3>"."Fabric :"." " .$person['Fabric']."</h3>"; 
         echo "<h3>"."Price :". " ".$person['Price']."</h3>"; 
       } 
   
   ?>

0
shoaibista Posts 8 Registration date Friday May 24, 2013 Status Member Last seen May 27, 2013
May 24, 2013 at 11:12 AM
may be problem in ur Connection.php

mysql_select_db("test")

check this
0