problem with code about adding to database
Posted: Fri May 08, 2009 6:44 pm
i need some help with my code, for some reason it's not working. I'm not the greatest at php so if i'm doing it completely wrong just tell me nicely
anyways here's my code
the problem i'm having is the insert part. i'm trying to put it in the friends table. as you can see it takes the id from the url and puts it to the database. then i have it write to the database the the friendname and your name for later recovery.
please help me with this, ANY help would be nice
Kedora19
anyways here's my code
Code: Select all
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
?>
<?php
include '../login/dbc.php';
//first open connection to your database
$id = mysql_real_escape_string($_GET['id']); //catch the id number from url, store it and escape slashes from possible attack.
$takeuser = mysql_query("SELECT * FROM users WHERE id='$id' LIMIT 1"); //Right now script check id number from url against the database
if (mysql_num_rows($takeuser) < 1) { //checks if we have that id number in our database
echo "User doesn't exist!"; //inform the user that we found 0 result
} else { //or if we found some
while ($row=mysql_fetch_array($takeuser)) { //Taking the result set
$sql="INSERT INTO friends (username, friendname)
VALUES
('$_SESSION[user]',' . $row['id'] . '";
} //closing the loop
} //closing the "if" statement
mysql_close($link); //and then we close connection
?>
please help me with this, ANY help would be nice
Kedora19