Not getting values from database in php

Discussion in 'PHP' started by Handsofmodder, Nov 6, 2008.

  1. #1
    I'm simply trying to get a value from the user_password from my database and display it, but it won't display the variable!

    <?php
    require "header.php";
    ?>
    <body>
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "admin", "password");
    mysql_select_db("booo_db");
    
    $query="SELECT user_password FROM users WHERE user_name='Herb'";
    $result=mysql_query($query);  
    $row=mysql_fetch_array($result);
    print $row['user_password'];
    ?>
    <?php
    require "footer.php";
    ?>
    PHP:
    Here's the URL
     
    Handsofmodder, Nov 6, 2008 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    replace the line with :

    
    mysql_connect("localhost", "admin", "password") or die ( mysql_error() );
    mysql_select_db("booo_db") or die ( mysql_error() );
    
    $query="SELECT user_password FROM users WHERE user_name='Herb'";
    $result=mysql_query("$query") or die ( mysql_error() );
    $row=mysql_fetch_assoc($result);
    
    PHP:
    and see whats the error
     
    ads2help, Nov 6, 2008 IP
  3. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Just posting here to follow the thread so I can help you later ;)
     
    elias_sorensen, Nov 6, 2008 IP
  4. Handsofmodder

    Handsofmodder Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I did that, but its still not working
    www.booo.vndv.com/login.php
     
    Handsofmodder, Nov 7, 2008 IP
  5. mcloide

    mcloide Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    have access to the mysql information schema database? Otherwise you would not be able to return the selected information.

    more stuff at: mcloide.wordpress.com
     
    mcloide, Nov 7, 2008 IP
  6. Handsofmodder

    Handsofmodder Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    my problem is still not resolved.
     
    Handsofmodder, Nov 9, 2008 IP
  7. shineDarkly

    shineDarkly Banned

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    your site is showing an error not related to db so posting the whole code if its not that big can help a lot
     
    shineDarkly, Nov 9, 2008 IP
  8. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    true values need a quotation around them

    I usually do something like this:


    <?php
    require "header.php";
    ?>
    <body>
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "admin", "password");
    mysql_select_db("booo_db");

    $user_name = $_POST['user']; // Or can be $_GET['user'] to get from the url

    $query = "SELECT user_password FROM users WHERE user_name='{$user_name}'";

    # Then I echo my line to make sure Im getting the proper var to pass:

    echo "SELECT user_password FROM users WHERE user_name='{$user_name}'";


    $result=mysql_query($query);
    $row=mysql_fetch_assoc($result); <----- NOTICE THE assoc and not array
    print $row['user_password'];
    ?>
    <?php
    require "footer.php";
    ?>
     
    IGiveMoney, Nov 9, 2008 IP
  9. keiths

    keiths Peon

    Messages:
    109
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Can you post the code from the whole page?
     
    keiths, Nov 9, 2008 IP
  10. tonsh

    tonsh Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Mybe some errors in header.php
     
    tonsh, Nov 10, 2008 IP
  11. Handsofmodder

    Handsofmodder Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    figured out the error. I was using the wrong username. It works perfectly now!
     
    Handsofmodder, Nov 10, 2008 IP