I'm having terrible trouble with two of my scripts. They are frustrating me to the point of quitting (joking, but seriously). You need to bear (bare?) in mind that I'm a complete beginner to this crap, so there may be some simple solution. That being said, I've had several people try and figure out what was going on, particularly with the search script, but no solution was found. We'll start with the friend system:
PHP troubles.
15
I'm having terrible trouble with two of my scripts. They are frustrating me to the point of quitting (joking, but seriously). You need to bear (bare?) in mind that I'm a complete beginner to this crap, so there may be some simple solution. That being said, I've had several people try and figure out what was going on, particularly with the search script, but no solution was found.
We'll start with the friend system:
Firstly, you need to understand that I didn't create this myself, I had someone with more experience help me out, but he got himself stuck so left it for someone else to fix up. I'll be honest, I don't really understand what's going on, but basically, I want it to be a standard friend system. That being where you can send a request, delete a request, block the user, etc.
Now, for the search script:
It works to an extent. That being it allows you to search their first or last name to get a result, but if you search the full name, then it returns as an error. I need it where you have the ability to search a full name and it returns with that specific name.
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...
Any more than that I get lost.
Thanks!
We'll start with the friend system:
PHP Code:
<?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 Code:
<?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 Code:
<?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...
PHP Code:
if($ == 1) {
echo "friends";
} else if($ == 2) {
echo "not friends";
}
Thanks!
- Andrew H
- [ 1 ] Thanks
- yestyle Banned
- [1] reply
- 723Media
- [ 1 ] Thanks
- [1] reply
- Alast
- [1] reply
- David Beroff
- ruchiforum2 Banned
- Alast
- Andrew H
- [ 1 ] Thanks
- [1] reply
- phpg
- jminkler
Next Topics on Trending Feed
-
15