Hello people.
I am struggling in getting the user ID (PK) from my user table into my leaderboard_1 table as a FK. I am confused on how to pass this information accross. Below is my code. At the moment a new leaderboard_1 record is created but it gives each record a value of 0 for id!?
?>
<?php
$self = $_SERVER['PHP_SELF'];
$country = $_POST['country'];
$username = $_POST['username'];
if( (!$country) or (!$username))
{
$form ="Please enter all the following fields to add yourself onto a leaderboard.";
$form.="<form action=\"$self\"";
$form.=" method=\"post\">Please enter your username: ";
$form.="<input type=\"text\" name=\"username\"";
$form.=" value=\"$username\"><br>Your country: ";
$form.="<input type=\"text\" name=\"country\"";
$form.=" value=\"$country\"><br>";
$form.="<input type=\"submit\" value=\"Submit\">";
$form.="</form>";
echo($form);
}
else
{
require_once('../mysql_connect.php');
#create the query
$sql = "select id from users where username=\"$username\"";
$uid = mysql_query( $sql)
or die( "Could not execute query" );
if( $uid != 0 )
{
$sql = "insert into leaderboard_1 (id,country,registration_date) values (\"$uid\",\"$country\", NOW())";
#execute the query
$result = @mysql_query($sql)
or die("Username or password incorrect");
if($result)
{ echo("You have been added to the leaderboard.");
}
}
else
{
header( "Location:$referer" ); exit();
}
}
?>
<?php
include ('./footer.inc'); // Include the HTML footer.
?>
Thanks for any help.
I am struggling in getting the user ID (PK) from my user table into my leaderboard_1 table as a FK. I am confused on how to pass this information accross. Below is my code. At the moment a new leaderboard_1 record is created but it gives each record a value of 0 for id!?
?>
<?php
$self = $_SERVER['PHP_SELF'];
$country = $_POST['country'];
$username = $_POST['username'];
if( (!$country) or (!$username))
{
$form ="Please enter all the following fields to add yourself onto a leaderboard.";
$form.="<form action=\"$self\"";
$form.=" method=\"post\">Please enter your username: ";
$form.="<input type=\"text\" name=\"username\"";
$form.=" value=\"$username\"><br>Your country: ";
$form.="<input type=\"text\" name=\"country\"";
$form.=" value=\"$country\"><br>";
$form.="<input type=\"submit\" value=\"Submit\">";
$form.="</form>";
echo($form);
}
else
{
require_once('../mysql_connect.php');
#create the query
$sql = "select id from users where username=\"$username\"";
$uid = mysql_query( $sql)
or die( "Could not execute query" );
if( $uid != 0 )
{
$sql = "insert into leaderboard_1 (id,country,registration_date) values (\"$uid\",\"$country\", NOW())";
#execute the query
$result = @mysql_query($sql)
or die("Username or password incorrect");
if($result)
{ echo("You have been added to the leaderboard.");
}
}
else
{
header( "Location:$referer" ); exit();
}
}
?>
<?php
include ('./footer.inc'); // Include the HTML footer.
?>
Thanks for any help.