Probably something easy, but I dunno understand. So any help is appriciated.
I have this function (functions.php):
function checkuser($tUsername, $tPassword) {
require('./admin/configforum.php'); //database configuration
$con_user= mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db);
$queryuser = "SELECT * FROM user WHERE username='$tUsername' AND password=MD5(CONCAT(MD5('$tPassword'), salt))";
$resultuser = mysql_query($queryuser);
if (mysql_num_rows($resultuser) == 0) {
$usercheck = "invalid";
}
else {
$objuser = mysql_fetch_object($resultuser);
$usercheck = "valid";
}
echo "$usercheck ";
mysql_close ($con_user); //close user connection
return $usercheck;
}
And I have the following PHP code in comment.php
<?
if (isset($_POST['action']) && $_POST['action'] == 'postcomment') {
require('./admin/functions.php');
$username = $_POST['tUsername'];
$password = $_POST['tPassword'];
$comment = $_POST['Tcomment'];
$newsid = $_GET['newsid'];
checkuser($username ,$password);
if ($$usercheck == 'valid') {
echo $usercheck;
insertcomment($comment,$newsid,$objuser->username,$objuser->userid);
echo "<script>setTimeout('window.close()',1000)</script>";
}
else {
echo $usercheck;
echo "Invalid username or password, please try again";
}
}
?>
Now in comments.php the variable $usercheck = empty, but in functions.php it's containing valid or invalid.
So my question is, how do I get the value of variable $usercheck into comment.php
(probably a stupid error from the user 😉 )