Hi there,
Did this before I saw rincewind456's post so a bit of cross-over ...
Firstly, comment out all your connection details as you did for password.
Your code has lot's of potential glitches, so here's a cleaned up version in my formatting style.
I'm not able to debug it (I would need access to your db) so check to see if haven't mis-spelled the field names etc. before trying it out.
Things to note:
1) Use back-ticks to enclose fieldnames and tablenames in SQL - not single-quotes.
2) My advice is NOT to embed variables in strings (cut in and out)
3) Do as much error-checking as you can
Anyway
<?php
$hostname = '***********';
$username = '***********';
$password = '***********';
$dbname = '***********';
$usertable = 'addfriend';
///////////////////////////////////////////////////////////////
// Do some checking to see if data is as expected
if(!isset($_POST['usernameone']) || $_POST['usernameone'] == ''){
die('[usernameone] not sent.');
} else {
$username1 = $_POST['usernameone'];
}
if(!isset($_POST['usernametwo']) || $_POST['usernametwo'] == ''){
die('[usernametwo] not sent.');
} else {
$username2 = $_POST['usernametwo'];
}
///////////////////////////////////////////////////////////////
mysql_connect($hostname,$username, $password)
or die('Unable to connect to database!');
mysql_select_db($dbname)
or die('Cannot select db');
$query = "
INSERT INTO `".$usertable."` (
`username1`
, `username2`
, `id`
) VALUES (
'".$username1."'
, '".$username2."'
, ''
)";
if(mysql_query($query)){
echo 'Query executed successfully';
} else {
echo 'Query failed';
}
mysql_close();
?>
Paul