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 />";
      }
    }
  }
?>

It would really help if you tell us what errors are you getting and also, by using code-tags to wrap your code.

Thanks for your concern.
the error for the addfriends.php says "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1",
while error for the request.php says "Unknown column 'userID' in 'where clause'".
I am kinda confused cus I have spent time trying to fix it but error still occur. can u offer me some help looking at my code plz.
Thankz

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

That piece of code does not make sense with the column names userid and userID. If I am not wrong, I believe php and mysql are case sensitive which means that the column name userid or userID will need to be adjusted to the proper casing. And by judging your last error, try replacing all instances of userID with userid. If that doesn't work, make sure you have the right casing by using phpmyadmin.

As cwarn23 has already mentioned, Php is case sensitive. The 'case sensitivity' of mysql depends on which server it is on. Linux is strictly case sensitive while windows is not.
You can try by changing userID to userid in your query and try again!

In user table u have been used primary key for userid

PRIMARY KEY (userid)

But, at the table creation u used userID.....

first check this one in phpmyadmin.....

if it was correct, than go to passes varibles..

friends2ID = $_GET["userID"];
$b = $_SESSION["gatekeeper"];

just try to echo these two variables...check the values coming or not....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.