...

View Full Version : MySQL Search In PHP



the-dream
03-08-2007, 06:02 PM
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!

cb_dethuong
03-08-2007, 06:18 PM
$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);

rafiki
03-08-2007, 06:21 PM
how about WHERE email LIKE $email?

JohnDubya
03-08-2007, 06:25 PM
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.

the-dream
03-08-2007, 06:41 PM
How would i use LIKE in the 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);

Inigoesdr
03-08-2007, 06:51 PM
$query = 'SELECT `Email` FROM `info` WHERE `Email` LIKE \'%' . $email . '%\'';
Like this ^



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum