SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How 2 Do THIS!!!!????

    What is that code so i can make a variable like $username know to look in the username field in database and tell you the information?

    Please reply fast.

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It would be simple select

    PHP Code:
    //connect to the base
    if(!($db = @mysql_connect(BASESERVERBASEUSERBASEPASS)))        //connect to base host
        
    die("Cannot connect to the base server.");
    if(!@
    mysql_select_db(BASENAME,$db)) //select base
        
    die("Database doesn't exist!!!");
    //this is the actual query
    $sql "SELECT * FROM your_table WHERE Username = '".$username."'";

    //perform query
    if(($result = @mysql_query($sql,$db)) == 0)      //Execute SQL query
    {
        echo 
    "\n<HR>Database error: <B>".mysql_error()."</B><BR><BR>\n";
        die(
    "Query was (<B>$sql</B>) in file <B>$PHP_SELF</B>");
    }

    //get results
    if(mysql_num_rows($result) == 0)
    {
              echo 
    "No results";
    }
    else
    {
             
    $user mysql_fetch_assoc($result);

    I haven't tried this code, so please check if everything is ok.
    -- Jelena --

  3. #3
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hope this helps. Did it as fast as i could


    PHP Code:

    $Query 
    = @mysql_query(Select from tablename); 
    if (!
    $Query) { 
     exit(
    '<p>Error retrieving stuff from database!<br />'
          
    'Error: ' mysql_error() . '<p>Try Later</p>'); 


    while (
    $Tablename mysql_fetch_array($Query)) { 
      
    $variable $Tablename['itemname']; 
      
    $variable2 $Tablename['itemname2']; 

    Regards

    Keith

  4. #4
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i am using kivisons code and on this part $Query = @mysql_query(Select * from tablename);

    what do i add or delete i tried deleting * and adding username but it didnt work

  5. #5
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you need

    SELECT * FROM table WHERE Username = '".$username."'
    -- Jelena --

  6. #6
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get the error

    Parse error: parse error, unexpected T_STRING in /home/chat/public_html/vars.php on line 3

    The code on that line is

    $Query = @mysql_query(SELECT * FROM table WHERE Username = '".$username."'

  7. #7
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Tidal Wave
    I get the error

    Parse error: parse error, unexpected T_STRING in /home/chat/public_html/vars.php on line 3

    The code on that line is

    $Query = @mysql_query(SELECT * FROM table WHERE Username = '".$username."'
    Change that to
    PHP Code:
    $Query = @mysql_query("SELECT * FROM table WHERE Username='$Username'"); 

  8. #8
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Error retrieving stuff from database!
    Error: No Database Selected

    Try Later

    THATS THE ERROR IM GETTING NOW

  9. #9
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You need to connect to db first as I posted before.
    -- Jelena --

  10. #10
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok it works now but the filewont work.

    Here is the vars.php file:

    <?
    include 'config.php';
    $Query = @mysql_query("SELECT * FROM $table WHERE Username='$Username'");
    if (!$Query) {
    exit('<p>Error retrieving stuff from database!<br />'.
    'Error: ' . mysql_error() . '<p>Try Later</p>');
    }

    while ($table = mysql_fetch_array($Query)) {
    $username = $table['username'];
    $variable2 = $Tablename['itemname2'];
    }
    ?>

    Here is the cpanel.php file:

    <?
    include 'config.php';
    include 'vars.php';
    echo "Hello $username here is your information:";
    echo "<br>";
    echo "First Name: $firstname";
    echo "<br>";
    echo "Last Name: $lastname";
    echo "<br>";
    echo "Email Address: $email";
    echo "<br>";
    ?>

    when i go to www.chat.ninechat.com/cpanel.php it should say hello $username ect.

  11. #11
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know how to make it work?

  12. #12
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If username is unique then you don't need while part as it will return only one row, but I do recommend to check if your query returned any results with

    PHP Code:
    if(mysql_num_rows($Query) == 0)
    //no results 
    after that just call mysql_fetch_assoc which will return associative array.
    PHP Code:
    $user mysql_fetch_assoc($Query
    Your username should be in $user['Username']
    -- Jelena --

  13. #13
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im confused you want me to make a php file named mysql_fetch_assoc.php and put in it:

    if(mysql_num_rows($Query) == 0)
    //no results

    then in the file cpanel.php change $username = $table['username'];
    to $user = mysql_fetch_assoc($Query)

    is that right?

  14. #14
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, I want you to call those functions after performing your query.

    And yes, echo in cpanel username as $user['Username']
    -- Jelena --

  15. #15
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im still confused isnt there a more simple way

  16. #16
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,001
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Huh... I don't think so.. This is the way I would use.
    -- Jelena --

  17. #17
    Non-Member
    Join Date
    Mar 2005
    Posts
    832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so is there anyone else who can help me?

  18. #18
    SitePoint Addict fesh's Avatar
    Join Date
    Jan 2005
    Location
    Jackson, New Jersey
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    honestly, Tidal, I think you need to read a tutorial. There's too much information for posts to help you. There are good ones on SitePoint, WebDev, even WebMonkey. Google "PHP MySQL tutorials" and I'm sure you'll get it.
    Fesh
    imagine what it's going to be like

  19. #19
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Couple Questions::

    1. Is your Username column in the database username or Username -- it matters.

    2. Is your $table variable set? Try echoing it out and see what happens. If you don't have a table name than it won't return any values. Also remember that variable set within a function are only available within the function itself unless set otherwise.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  20. #20
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW -- What's not working now? Can you post the code as it appears now? I'd be more than happy to give it a shot!
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •