Also, as a continuation of this, I have another problem (I did not want to post another thread, this way all of the problems with my friend request code are in one place).
Code: Select all
<?php
include("database.php");
function findString($startPoint, $endPoint, $source) {
$m=array();
preg_match_all('/' . preg_quote($startPoint, '/') . '([^)]+)'. preg_quote($endPoint, '/').'/i', $source, $m);
return $m[1][0];
}
$fr = mysql_fetch_object(mysql_query("select friendrequests from notes_notes where email = '$usr' and Password = '$pass'")) -> friendrequests;
$usr = $_COOKIE['loggeduser'];
$pwd = $_COOKIE['loggedpass'];
$user = mysql_query("select count(*) as count from notes_notes where email = '$usr' and Password = '$pwd'");
$oldOutPut = 0;
if ($user >= 1) {
if ($fr != "") {
$p = 0;
$offset = 0;
$len = strlen($fr);
$ppp = "p".$p;
$ppl = "p".$p."len";
$ppo = "p".$p."pos";
for ($i = 1; $i <= $len; $i++) {
if (strpos($fr,",",$offset) != false) {
$offset = strpos($fr,",",$offset)+1;
$p = $p + 1;
$friend = findString($oldOutPut,$offset,$fr);
${$ppp} = $friend;
${$ppo} = 0;
${$ppl} = strlen($friend);
$oldOutPut = $offset;
echo <<<END
<div style="width:100%;height:10%;">
$friend
<input type="Submit" name="submit".$p value="Add as friend">
<input type="Submit" name="cancel".$p value="Not now">
</div>
END;
}
}
}
else {
echo <<<END
<div style = "width:50%;height:100%">
Sorry, you have no friend requests
</div>
END;
}
}
$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,"",$num,$len+1);
$oldfriends = mysql_query("select friends from notes_notes where email = '$usr' and Password = '$pwd'");
$old = $oldfriends.findString($num,$num+$len,$fr);
mysql_query("UPDATE notes_notes SET friends = '$old' WHERE email = '$usr' and Password = '$pass'");
}
}
?>
The code above *should* check if you have any friend requests, if so create a for loop which sets the variables $p(1,2,3,4,5,6,7), $p(1,2,3,4,5,6,7)len, $p(1,2,3,4,5,6,7)pos so they can be recalled later to update the button being pressed. However, even though the code in the other problem I had here detects that in the friend requests there is text, this fails to so does not post the correct message. Can anybody see any errors in this code. Also, findString is a function I made which should get the text between two points in a string.