get data from mysql

Discussion in 'PHP' started by ediri, Nov 16, 2007.

  1. #1
    i used mysql as database,apache as server and php language.When i'm write this code for get data from mysql database table it shows HTTP 500 internal server error and page is not displayed.Actually i'm very very newer for the php.So pls help me.
    Thank you.
    ediri
    <html>
    <head>
      <title>show datas</title>
    </head>
    <body>
    <h1>show data</h1>
    </body>
    <?php
    // we must never forget to start the session
    //session_start();
    
    //$errorMessage = '';
    
    
    
    // makes sure they filled it in
    
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbname = 'detail';
    
    
    
    if (!($db = mysql_connect($dbhost, $dbuser))){ 
      die("Can't connect to mysql.");     
    }else{ 
      if (!(mysql_select_db("$dbname",$db)))  { 
        die("Can't connect to db."); 
      } 
    } 
       
    /*$username  = addslashes($username);
    $password = addslashes($password);
    $name = addslashes($name);
    $address = addslashes($address);*/
       // check if the user id and password combination exist in database
       $sql = "SELECT username,name,address
               FROM detail";
              
    
       $result = mysql_query($sql) 
                 or die('Query failed. ' . mysql_error()); 
    
    //$num_results = mysql_num_rows($result);
    while($row = mysql_fetch_assoc($result))
    
    {
      echo "username :{$row['username']} <br>" .
             "name : {$row['name']} <br>" . 
             "address : {$row['address']} <br><br
    }
    
    
    
    
       /*if (mysql_num_rows($result) == 1) {
          // the user id and password match, 
          // set the session
          $_SESSION['db_is_logged_in'] = true;
          // after login we move to the main page
          header('Location: NormalUser.php');
          exit;
       } else {
          $errorMessage = 'Sorry, wrong user id / password';*/
       
    mysql_close($conn);
    
    
    ?>
    
    
    </html>
    
    Code (markup):

     
    ediri, Nov 16, 2007 IP
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    If you are getting HTTP 500 internal server error than its Apache Problem. There is something wrong with your Apache server installation/Configuration.
     
    greatlogix, Nov 16, 2007 IP
  3. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #3
    you probably did not install php properly, if you're quite new try installing pre packaged installers like xampp etc
     
    serialCoder, Nov 16, 2007 IP
  4. jakomo

    jakomo Well-Known Member

    Messages:
    4,262
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    138
    #4
    Yup, if you bought a hosting contact them.

    Best,
    Jakomo
     
    jakomo, Nov 16, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    This can also be caused by a corrupt or unrecognized .htaccess file.

    See if there's one and try to remove it temporary.
     
    nico_swd, Nov 16, 2007 IP