Results 1 to 32 of 32

Thread: Searching mySQL database!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509

    Searching mySQL database!!

    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:44 PM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Hi raladin.

    Do you have an actual question? You've got to learn PHP and MySQL of course. Beyond that, we cannot help you yet. We're here to solve problems, not write programs.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:43 PM.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Searching mySQL database!!

    Originally posted by raladin
    Hi all..

    First of all I want to introduce my self because I'm sure you are saying "Who is this guy!!! a very stupid guy " so :

    I'm 14 years old.. in the 9th grade (At school).. you know I don't have the enough time to learn much about PC languages... so I'm now prepairing to get CompTIA A+ and I know of course HTML and PhotoShop..... Also I have many certificates from : the Associated Board of the Royal Schools of Music - Lodon in playing Classical Piano.. and I'm prepairing for the Dip. the next year..
    And I will receive a FULL ScholarShip from Carnegie Mellon as they said me and my brother..

    I don't play the piano, but I can use winamp really well. I have no certificates for it though. However, I can easily see how your certifications with the pianos are going to help you with your project.




    I made 90% of my new project (E-Learning System) and I want now something in PHP (I'm new to PHP).. I want to make a PHP page for the admin to activate users accounts.. so a PHP page with a TextBox (UserName) with an "Activate" button.. the admin enters the user name for any user.. and then press the "Activate".. the PHP page will search the database for that username.. and when it find its row there it will change a value in the database (In that row).. the value that will be changed is under the field "Activation" from "Not Activated" to "Activated".. so the user now is activated..

    Hope you got my meaning.. and sorry for my bad English
    Example code off google:

    PHP Code:

    function dbConnect()
    {
        
    //define the database connection information
        
    $dbHost "localhost";
        
    $dbUser "username";
        
    $dbPass "password";
        
    $dbName "nameofdatabase";


        
    //connect to the mysql server
        
    $link = @mysql_connect($dbHost$dbUser$dbPass);

        
    //return success or failure of connection
        
    if(!$link)
        {
            
    //report error
            
    echo "Could not connect to server";
            exit;
        }

        
    //select the database
        
    if(!@mysql_select_db($dbName))
        {
            
    //report error
            
    echo "Could not select database";
            exit;
        }


    Once connected (using similar-to-above code), you can query it:

    PHP Code:
    $result mysql_query("SELECT * FROM myusers WHERE username='" $storedvar "'",$db);
    //$storedvar retrieved from the previous page

    if mysql_result($result,0,"activated") == "0"
    {
    $result2mysql_query("UPDATE myusers SET activated='1' WHERE username = '" $storedvar "'"$db)

    This is just a rough example. GO through this link here for a good DB tutorial:

    http://hotwired.lycos.com/webmonkey/...tw=programming







    Notice : I attached my CV and my brothers' CV to see them
    Thank you. I'll forward these to Newt Gingrich ASAP. He'll know what to do with you two.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:47 PM.

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I think you googled bad code. Much easier to do:

    Code:
    function dbConnect() { 
        //define the database connection information 
        $dbHost = "localhost"; 
        $dbUser = "username"; 
        $dbPass = "password"; 
        $dbName = "nameofdatabase"; 
    
        //connect to the mysql server 
        $link = @mysql_connect($dbHost, $dbUser, $dbPass) or die('Could not connect to server.'); 
        mysql_select_db($dbName, $link) or die('Could not select database.');
    }
    Maybe that's just my opinion, though.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:47 PM.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by The Hobo
    I think you googled bad code.
    I googled for "how would hobo connect to mysql?"


  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Must I store the variable MD5.. or I can import it then convert it to MD5 then echo it?
    What variable
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:47 PM.

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by raladin
    Thanks The Hobo for your reply.. it is the same..
    No, it's not the same. Mine is a few lines shorter. Plenty of characters shorter. Shorter means less file size. And in a big project, that matters to some.

    Originally posted by raladin
    but mendhak gave me a code also to insert the value to the database..
    Yes, I know this. Thanks.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by mendhak
    I googled for "how would hobo connect to mysql?"
    Well, google lies. It's all lies!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    In case you guys don't know, raladin here is trying to make a super-secure app that would transfer the user's hard drive serial number to his website.

    It's 4 lines of code that retrieves the serial number, and 2000 lines of code for securing it.

    Now he's at the PHP part.

    And he plays the piano as well.

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks for the wrap up. Sounds like fun.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    I think it'd probably be alot easier to control the database from the VB program, instead of relying on some PHP script.. I guess it would depend on how well he knows VB though.
    Like Archer? Check out some Sterling Archer quotes.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:48 PM.

  17. #17
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by raladin
    Waiting your help..
    On what? You didn't ask a question...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:48 PM.

  19. #19
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    The same way you're comparing user names in the code you provided.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:48 PM.

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2003
    Posts
    509
    Inva
    Last edited by raladin; Mar 29th, 2014 at 10:48 PM.

  22. #22
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I personally think the easiest thing to do is to use mysql_fetch_array rather than mysql_fetch_row.

    Code:
    $rows = mysql_query("SELECT * FROM tblName") or die(error_thing_here);
    $row = mysql_fetch_array($row) or die(error_thing_here);
    
    // Now you can access by field name:
    if ($password = $row['password_field_name']) {
        // Do something
    }
    That way you don't have to worry about whether it's the 1st, 2nd, or 3rd field, you can just access it by what you named it.

    Much easier, in my opinion.

    But yes, you're on the right track.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  23. #23
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Originally posted by kows
    I think it'd probably be alot easier to control the database from the VB program, instead of relying on some PHP script.. I guess it would depend on how well he knows VB though.
    Control a MySQL database from VB?
    Errr...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  24. #24
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    Control a MySQL database from VB?
    Errr...
    Why Errr?

    It can be done through VB, although most of the hosts I've had in my life don't allow outside connections to the database.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  25. #25
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    why err? it can be done.. I'm making a project right now that does it.. Maybe I should have used "interact with" instead of "control"?

    Most web hosts don't allow remote connections, but some do.. most good ones I've found allow it.
    Like Archer? Check out some Sterling Archer quotes.

  26. #26
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm sure I wouldn't be too happy if anyone could connect to my database and start trying to log in.

    I should mention that my host allows you to add IP addresses to allow certain remote machines to connect. In that case, that's a good method, as you can control who connects to your database.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  27. #27
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But unsuited for the situation.

    How do you deal with a MySQL database from VB? MyODBC?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  28. #28
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    Unsuitable for the situation? The guy is using a VB application to basically update the database and check if some user information is correct, and he's just using PHP as a middle man. I suggested it just so that he would cut out PHP and leave it as plain VB and MySQL.

    By the way, yeah, MyODBC is used for VB/MySQL interaction.
    Like Archer? Check out some Sterling Archer quotes.

  29. #29
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I was referring to the "accept specific IPs". Since every user of his app needs to connect there, that's quite a lot of IPs to activate, aside from the impossibility of finding out which.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  30. #30
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Plus, dialup users have changing IPs, so each time they connected to the internet, they'd have to give you their IP to allow the connection.

    Unless the server allowed any computer to connect. And that's not cool, if you ask me.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  31. #31
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    As long as the passwords a secure and there's always the latest security updates...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  32. #32
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    As long as the passwords a secure and there's always the latest security updates...
    Whatever floats your boat.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width