[SOLVED]Search Bar Issue.
Posted: Sun Aug 07, 2011 5:17 am
I am trying to make a user search bar for a sort of social network type thing so you can search for friends, and it returns their name, email, description, and buttons saying [text]'Send friend request'[/text] or [text]'View Profile'[/text]
I have been working on it for quite a while but cannot see why it returns nothing (eg I have two users, complete with names and emails and descriptions, called Jeremy and Bethany (Test accounts, not anything linking to me), and it returns:
[text]Search: Jer[/text]
When it should return:
[text]Search: Jer, Name = Jeremy, Email = Jeremy@fakeemailaddress.co.uk, Description = Just on here for a while, Add as friend[/text]
It also does not work even with the full address:
Also, I am trying to condense all of my PHP code onto one website instead of seperated, if you can see anyways I could make the length of code shorter, please do tell 
I have been working on it for quite a while but cannot see why it returns nothing (eg I have two users, complete with names and emails and descriptions, called Jeremy and Bethany (Test accounts, not anything linking to me), and it returns:
[text]Search: Jer[/text]
When it should return:
[text]Search: Jer, Name = Jeremy, Email = Jeremy@fakeemailaddress.co.uk, Description = Just on here for a while, Add as friend[/text]
It also does not work even with the full address:
Code: Select all
<?php
ob_start();
include("database.php");
echo <<<END
<head>
<title>Blackboard</title>
</head>
END;
echo <<<END
<div>
<FORM NAME ="form1" METHOD ="POST" ACTION = "search.php">
<INPUT TYPE = "Text" VALUE ="" NAME = "search">
<INPUT TYPE = "Submit" Name = "Search1" VALUE = "Search">
</div>
END;
if (isset($_POST['Search1'])) {
$term = $_POST['search'];
$term2 = $term.'%';
$search = mysql_query('SELECT email FROM notes_notes WHERE Username LIKE "$term2"') or die(mysql_error());
$user = $_COOKIE['loggeduser'];
$search2 = mysql_fetch_array($search) or die(mysql_error());
$search8 = $search2 -> Username;
echo $search8;
$friends = mysql_query("select friends from notes_notes where email like '$user'");
$friends2 = mysql_fetch_object($friends);
$friends3 = $friends2->friends;
$friendreq = mysql_query("select friendrequests from notes_notes where email like '$user'");
$friendreq2 = mysql_fetch_object($friendreq);
$friendreq4 = $friendreq2->friendrequests;
echo $term;
$p = 0;
foreach ($search2 as &$value) {
$p=$p+1;
echo $value;
$search4 = $value->Username;
$desc = mysql_query("select description from notes_notes where email like '$value'");
echo $value;
$desc2 = mysql_fetch_object($desc);
$desc3 = $desc->description;
${n.$p} = $value;
if (strpos($friends3,$value) == false) {
echo <<<END
<div style="height:30px; width:300px;">
$value
<br>
$desc3
<input type="Submit" value="Send friend request" name = "friend$p">
</div>
END;
}
else
{
echo <<<END
<div style="height:30px; width:300px;">
$value
<br>
$desc3
<input type="Submit" value="View Profile" name = "only$p">
</div>
END;
}
}
unset($value);
} else {
}
$a = 0;
for ($i = 1; $i <= $len; $i++) {
$a = $a + 1;
$name = "only".$a;
if (isset($_POST[$name])) {
$name = ${n.$a};
setcookie("loggedfriend",$_COOKIE['loggeduser'],time()+60*60*24);
echo <<<end
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url='guestnotes.php'">
</head>
end;
}
}
$z = 0;
for ($i = 1; $i <= $len; $i++) {
$z = $z + 1;
$namen = "friend".$z;
if (isset($_POST[$namen])) {
$name = ${n.$a};
$player = $_COOKIE['loggeduser'];
$oldfriend = mysql_query("select friendrequests from notes_notes where email = '$name'") or die(mysql_error());
$oldfriend2 = mysql_fetch_object($oldfriend);
$oldfriend3 = $oldfriend2 -> friendrequests;
$old = $oldfriends3.$player;
mysql_query("UPDATE notes_notes SET friendrequests = '$old' WHERE email = '$name}'") or die(mysql_error());
}
}
?>