Multiple Issues (MySQL and text field searching)
Posted: Fri Aug 05, 2011 1:01 pm
I am having multiple issues with a sort of social network mixed with a online jotter. I am currently making a search bar to search for friends, and a thing to add friends who have sent you a friend request.
Search Bar
Above is the code used for the search bar which should search through the database for names which begin with the text in the query (Typing Pine would come up with Pinetrees, Pineapple, etc.) and then print these in dividers which also contain a description of them and, if they are not friends, an add to friends button, or a view profile button. When this is run with a username from the database, such as my two test users (Jeremy and Bethany (Nothing to do with me in real life), it returns nothing, wether it is 'Jer' (For Jeremy) or Bethany (For Bethany). Am I missing a vital part needed?
Friend viewer
This is probably much simpler, the update line in my add friends page is not running. The code is:
And the error message is
[text]Parse error: syntax error, unexpected T_STRING on line 68[/text]
(Please note, the lines posted are 58-70, the error line is
)
Can anybody help on either of the issues?
Search Bar
Code: Select all
<?php
ob_start();
include("database.php");
echo <<<END
<div>
<FORM NAME ="form1" METHOD ="POST" ACTION = "search.php">
<INPUT TYPE = "Text" VALUE ="" NAME = "search">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Search">
</div>
END;
if (isset($_POST['Submit1'])) {
$term = $_POST['search'];
$term2 = $term.'%';
$search = mysql_query('SELECT Username FROM notes_notes WHERE Username LIKE "$term2"') or die(mysql_error());
$user = $_COOKIE['loggeduser'];
$search2 = mysql_fetch_array($search) or die(mysql_error());
$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;
foreach ($search as &$value) {
$search4 = $value->Username;
$desc = mysql_query("select description from notes_notes where Username like '$value'");
echo $value;
$desc2 = mysql_fetch_object($desc);
$desc3 = $desc->description;
if (strpos($friends3,$value) == false) {
echo <<<END
<div style="height:30; width:300;">
$value
<br>
$desc3
<input type="Submit" value="Send friend request" name = "friend">
</div>
END;
}
else
{
echo <<<END
<div style="height:30; width:300;">
$value
<br>
$desc3
<input type="Submit" value="View Profile" name = "only">
</div>
END;
}
}
unset($value);
} else {
echo "Failed";
}
?>Friend viewer
This is probably much simpler, the update line in my add friends page is not running. The code is:
Code: Select all
$usr = $_COOKIE['loggeduser'];
$pwd = $_COOKIE['loggedpass'];Code: Select all
$a = 0;
for ($i = 1; $i <= $p; $i++) {
$a = $a + 1;
$name = "submit".$a;
if (isset($_POST[$name])) {
$num = "$p".$a."pos";
$len = "$p".$a."len";
substr_replace($fr,"",${"p".$a."pos"},${"p".$a."len"}+1);
$oldfriends = mysql_query("select friends from notes_notes where email = '$usr' and Password = '$pwd'");
$old = $oldfriends.substr($fr,${"p".$a."pos"},${"p".$a."len"}).","
mysql_query("UPDATE notes_notes SET friends = '$old' WHERE email = '$usr' and Password = '$pwd'") or die(mysql_error());
}
}[text]Parse error: syntax error, unexpected T_STRING on line 68[/text]
(Please note, the lines posted are 58-70, the error line is
Code: Select all
mysql_query("UPDATE notes_notes SET friends = '$old' WHERE email = '$usr' and Password = '$pwd'") or die(mysql_error());Can anybody help on either of the issues?