Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Exclamation MySQL Search In PHP

    Could Someone please help me i am trying to search a singe column ' Email ' from my table ' info ' in my database ' addressbook ' how is this done? Please help!

  • #2
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    $email = "anything@youlike.domain";
    $connect  = @mysql_connect("localhost","user","pass") or die("Could not connect to database");
    $db          = @mysql_select_db("db_name");
    $query     = "SELECT email FROM info WHERE email='".$email."' ";
    $mksql     =@mysql_query($query);
    $fetch     =@mysql_fetch_array($mksql);
    echo $fetch['email'];
    @mysql_free_result($mksql);
    @mysql_close($connect);

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    how about WHERE email LIKE $email?

  • #4
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by the-dream View Post
    Could Someone please help me i am trying to search a singe column ' Email ' from my table ' info ' in my database ' addressbook ' how is this done? Please help!
    Read the PHP/MySQL tutorials that are listed in the sticky post at the top of the PHP forum. That will give you a good start. The one that helped me the most when I was starting out was http://www.php-mysql-tutorial.com/

    Good luck.

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    How would i use LIKE in the code:
    PHP Code:
    $email $_GET['search'];
    $connect  = @mysql_connect("localhost","root","root") or die("Could not connect to database");
    $db          = @mysql_select_db("addressbook");
    $query     "SELECT Email FROM info WHERE Email='".$email."' ";
    $mksql     =@mysql_query($query);
    $fetch     =@mysql_fetch_array($mksql);
    echo 
    $fetch['Email'];
    @
    mysql_free_result($mksql);
    @
    mysql_close($connect); 

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by the-dream View Post
    PHP Code:
    $query 'SELECT `Email` FROM `info` WHERE `Email` LIKE \'%' $email '%\''
    Like this ^


  •  

    Posting Permissions

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