PHP troubles.
We'll start with the friend system:
<?php
error_reporting(E_ALL);
require_once("sSQL.php");
login1("localhost", "root", "", "users");
$id = "1";
$u_id = $_GET['id'];
$s = $_GET['s'];
$back = $_SERVER['HTTP_REFERER'];
$ip = $_SERVER['REMOTE_ADDR'];
$a = mysql_query("SELECT * FROM `friends` WHERE `user_id`='$id' AND `friend_id`='$u_id' OR `user_id`='$u_id' AND `friend_id`='$id'") or die(mysql_error());
$b = fetch($a);
$c = num($a);
$user_id = $b['user_id'];
$friend_id = $b['friend_id'];
$stage = $b['stage'];
if($c == 0)
{
// they're not friends, but id wants to be friends.
if($s == 1)
{
// Add friend
mysql_query("INSERT INTO `friends` (`user_id`, `friend_id`, `stage`, `ip`) VALUES ('$id', '$u_id', '$s', '$ip')")or die(mysql_error());
header("Location: $back");
}
}
else
{
// remove request sent
if($id == $user_id && $stage == 1)
{
mysql_query("DELETE FROM `friends` WHERE `user_id`='$id' AND `friend_id`='$u_id' AND `stage`='1'") or die(mysql_error());
header("Location: $back");
}
else
if($id == $friend_id && $stage == 1)
{
// Ew, I don't wanna be your friend.
mysql_query("DELETE FROM `friends` WHERE `user_id`='$u_id' AND `friend_id`='$id' AND `stage`='1'") or die(mysql_error());
header("Location: $back");
}
else
if($u_id == $friend_id && $s == 2)
{
// okay, let's be friends. I'll accept.
mysql_query("UPDATE `friends` SET `stage`='$s' WHERE `user_id`='$u_id' AND `friend_id`='$id' AND `stage`='1'") or die(mysql_error());
mysql_query("INSERT INTO `friends` (`user_id`, `friend_id`, `stage`, `ip`) VALUES ('$id', '$u_id', '$s', '$ip')")or die(mysql_error());
header("Location: $back");
}
else
if($id == $user_id && $stage == 2 || $id == $friend_id && $stage == 2)
{
// Screw you, I'm deleting you!
mysql_query("DELETE FROM `friends` WHERE `user_id`='$u_id' AND `friend_id`='$id' AND `stage`='2'") or die(mysql_error());
mysql_query("DELETE FROM `friends` WHERE `user_id`='$id' AND `friend_id`='$u_id' AND `stage`='2'") or die(mysql_error());
header("Location: $back");
}
}
if($s == 3)
{
// Block the scum!!!
mysql_query("DELETE FROM `friends` WHERE `user_id`='$u_id' AND `friend_id`='$id'") or die(mysql_error());
mysql_query("DELETE FROM `friends` WHERE `user_id`='$id' AND `friend_id`='$id'") or die(mysql_error());
mysql_query("INSERT INTO `friends` (`user_id`, `friend_id`, `stage`, `ip`) VALUES ('$id', '$u_id', '$s', '$ip')")or die(mysql_error());
mysql_query("INSERT INTO `friends` (`user_id`, `friend_id`, `stage`, `ip`) VALUES ('$u_id', '$u_id', '$s', '$ip')")or die(mysql_error());
header("Location: $back");
}
?>
<?php
error_reporting(E_ALL);
require_once("sSQL.php");
login1("localhost", "root", "", "users");
$a = mysql_query("SELECT * FROM `friends` WHERE `user_id`='$id' AND `friend_id`='$user_id' OR `user_id`='$user_id' AND `friend_id`='$id'") or die(mysql_error());
$b = fetch($a);
$c = num($a);
$user_id2 = $b['user_id'];
$friend_id = $b['friend_id'];
$stage = $b['stage'];
if($id != $user_id) {
if($c == 0)
{
// Add friend!
echo "<a href='request.php?id=$user_id&s=1'>Add Friend</a>";
}
else
{
if($id == $user_id && $stage == 1)
{
// Cancel friend request
echo "<a href='request.php?id=$friend_id&s=1'>Remove Request</a>";
}
else
if($id == $friend_id && $stage == 1)
{
// Don't accept friend & Accept
echo "<a href='request.php?id=$user_id2&s=2'>Accept</a>";
echo "<a href='request.php?id=$user_id2'>Decline</a>";
}
else
if($id == $user_id && $stage == 2 || $id == $friend_id && $stage == 2)
{
// Remove friend
echo "<a href='request.php?id=$user_id2'>Remove as friend</a>";
}
}
// Block..........
echo "<a href='request.php?id=$user_id&s=3'>Block</a>";
}
?>
Now, for the search script:
<?php
if (isset($_POST['search'])) {
$searchq = $_POST['search'];
$query = mysql_query("SELECT * FROM users WHERE first_name = '$searchq' OR last_name= '$searchq'") or die("An error occurred.");
$count = mysql_num_rows($query);
if ($count == 0) {
$output = 'There were no search results!';
} else {
while($row = mysql_fetch_array($query)) {
$fname = $row['first_name'];
$lname = $row['last_name'];
$user_id = $row['user_id'];
echo '<div> '.$fname.' '.$lname.'</div>';
}
}
print("$output");
}
?>
If you know any of these solutions, please explain to me what is going on so maybe I can grasp what's happening. Right now PHP is a blur. To put this into perspective:
Try speaking a language you've never seen before.
That is what I feel like at the present time.
I'd also like to ask a question, how long before someone beginning can begin to actually make scripts without the need of tutorials and/or assistance? I've been learning for 3~ weeks, but in total in terms of hours, probably around 24-48 hours has been spend creating/learning scripts. I can understand things like...
if($ == 1) {
echo "friends";
} else if($ == 2) {
echo "not friends";
}
Thanks!
http://graphicriver.net/user/723media/portfolio
Are you ready to finally launch your product?
http://graphicriver.net/user/723media/portfolio
Are you ready to finally launch your product?