Right, I more or less fixed it, however this code gives out a weird answer. It should go from:
friends friend requests
Jeremy,Bethany,
to
friends friend requests
Jeremy, Bethany,
yet instead it goes one character at a time:
y
my
emy
remy
eremy
Jeremy.
Does anyone have any way to fix this?
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];
}
$usr = $_COOKIE['loggeduser'];
$pwd = $_COOKIE['loggedpass'];
$fr = mysql_fetch_object(mysql_query("select friendrequests from notes_notes where email = '$usr' and Password = '$pwd'")) -> friendrequests;
$user = mysql_query("select count(*) as count from notes_notes where email = '$usr' and Password = '$pwd'");
$user2 = mysql_fetch_object($user);
$user3 = $user2 -> count;
$oldOutPut = 0;
if ($user3 >= 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;
$outPut = $offset - $oldOutPut;
$friend = substr($fr,$oldOutPut,$outPut);
${$ppp} = $friend;
${$ppo} = 0;
${$ppl} = strlen($friend);
$oldOutPut = $offset;
$submit = "Submit".$p;
$cancel = "Cancel".$p;
echo <<<END
<div style="width:100%;height:10%;">
$friend
<br>
<FORM NAME ="form1" METHOD ="POST" ACTION = "friends.php">
<INPUT align="centre" TYPE = "Submit" Name = "$submit" VALUE = "Enter">
<input type="Submit" name='$cancel' 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 <= $len; $i++) {
$a = $a + 1;
$name = "Cancel".$a;
if (isset($_POST[$name])) {
$num = "$p".$a."pos";
$len = "$p".$a."len";
$test = mysql_query("select friendrequests from notes_notes where email = '$usr' and Password = '$pwd'") or die(mysql_error());
$test3 = mysql_fetch_object($test);
$test4 = $test3 -> friendrequests;
$test2 = substr_replace(($test4.","),"",${$num},${$len}+1);
echo $test2;
mysql_query("UPDATE notes_notes SET friendrequests = '$test2' WHERE email = '$usr' and Password = '$pwd'") or die(mysql_error());
$tes = mysql_query("select friendrequests from notes_notes where email = '${'p'.$a}'") or die(mysql_error());
$tes3 = mysql_fetch_object($tes);
$tes4 = $tes3 -> friendrequests;
$tes2 = substr_replace(($tes4.","),"",${$num},${$len}+1);
mysql_query("UPDATE notes_notes SET friendrequests = '$tes2' WHERE email = '${'p'.$a}'") or die(mysql_error());
}
}
$a = 0;
for ($i = 1; $i <= $len; $i++) {
$a = $a + 1;
$name = "Submit".$a;
if (isset($_POST[$name])) {
$num = "$p".$a."pos";
$len = "$p".$a."len";
echo ${$len};
echo ${$num};
$test = mysql_query("select friendrequests from notes_notes where email = '$usr' and Password = '$pwd'") or die(mysql_error());
$test3 = mysql_fetch_object($test);
$test4 = $test3 -> friendrequests;
$test2 = substr_replace($test4,"",${$num},${$len}+1);
echo $test2;
mysql_query("UPDATE notes_notes SET friendrequests = '$test2' WHERE email = '$usr' and Password = '$pwd'") or die(mysql_error());
$tes = mysql_query("select friendrequests from notes_notes where email = '${'p'.$a}'") or die(mysql_error());
$tes3 = mysql_fetch_object($tes);
$tes4 = $tes3 -> friendrequests;
$tes2 = substr_replace(($tes4),"",${$num},${$len});
mysql_query("UPDATE notes_notes SET friendrequests = '$tes2' WHERE email = '${'p'.$a}'") or die(mysql_error());
$oldfriends = mysql_query("select friends from notes_notes where email = '$usr' and Password = '$pwd'") or die(mysql_error());
$oldfriends2 = mysql_fetch_object($oldfriends);
$oldfriends3 = $oldfriends2 -> friends;
$oldfriend = mysql_query("select friends from notes_notes where email = '${'p'.$a}'") or die(mysql_error());
$oldfriend2 = mysql_fetch_object($oldfriend);
$oldfriend3 = $oldfriend2 -> friends;
$old = $oldfriends3.substr($fr,${"p".$a."pos"},${"p".$a."len"});
echo $old;
$older = $oldfriend3.substr($fr,${"p".$a."pos"},${"p".$a."len"});
echo $older;
mysql_query("UPDATE notes_notes SET friends = '$older' WHERE email = '${'p'.$a}'") or die(mysql_error());
mysql_query("UPDATE notes_notes SET friends = '$old' WHERE email = '$usr' and Password = '$pwd'") or die(mysql_error());
}
}
?>