Hello Guys, Im having a problem with my request code. I need to send a request to a friend and it should appear on the friends page when the friend log in. then if the freind accept it, it should get updated in the freinds table , ut I seem to be having some errors with the code. I've sat all night trying to fixed it but I seem to be putting more error that than never. I have attached my login and request codes along with the users and friends table to help u understand what im talking about.
Pls I need help.
Thanks guys.
I've created two tables, one for users and one for friends
// users table
CREATE TABLE `kclove`.`users` (
`userID` INT( 11 ) NOT NULL AUTO_INCREMENT COMMENT 'auto_increment',
`name` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL ,
`username` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL ,
`password` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL ,
`interest` VARCHAR( 255 ) NULL DEFAULT NULL ,
PRIMARY KEY ( `userid` )
) ENGINE = MYISAM CHARACTER SET latin1 COLLATE latin1_swedish_ci
//Friends2
CREATE TABLE `kclove`.`friends2` (
`friends2ID` INT( 11 ) NOT NULL AUTO_INCREMENT COMMENT 'auto_increment',
`person1` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL ,
`person2` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL ,
`status` INT( 11 ) NULL DEFAULT '0',
PRIMARY KEY ( `ID` )
) ENGINE = MYISAM CHARACTER SET latin1 COLLATE latin1_swedish_ci
// my Login page:
<?php
session_start();
$b = $_SESSION[gatekeeper];
$conn=mysql_connect("localhost","root", "mysql");
mysql_select_db("Kclove");
$b = $_POST ["username"];
$c = sha1($_POST["password"]);
$q = ("select * from users where username = '$b' AND password = '$c'");
//echo "query is $q<br/>";
$result=mysql_query($q) or die(mysql_error());
if (mysql_num_rows($result)==0)
{
echo "invalid Username or Password!";
}
else
{
$_SESSION["gatekeeper"] = $b;
header ("location:index.php");
}
?>
// my request page
<?php
session_start();
friends2ID = $_GET["userID"];
$b = $_SESSION["gatekeeper"];
include ('connect.php');
$query = mysql_query("SELECT * FROM users WHERE userID = '" . $_SESSION["gatekeeper"] . "'");
if(mysql_num_rows($query) > 0)
{
while($row = mysql_fetch_array($query))
{
$_query = mysql_query("SELECT * FROM friends2 WHERE friends2ID = '" . $row["person1"] . "'");
while($_row = mysql_fetch_array($_query))
{
echo $_row["username"] . " wants to be your friend. ""<a href='profile.php?accept=".$_row["name"] . "\">Accept?</a><br />";
}
}
}
?>