...

View Full Version : php and javascript



kurdishvoice
11-01-2004, 01:00 PM
hi all

im new to php so i need help. I currently have a voice chat which is coded in javascript, i have a registration system in php that works fine and users can register, but when i want to pass the variables from the php file like $username to the voicechat javascript it does not work, i am not sure at this part. here is some of the code.

Here is the form in html


<form action="checkuser.php" method="post" name="test" id="">
<table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<INPUT onclick=javascript:login() type=button value=login name=B1>
<td width="22%">Username</td>
<td width="78%"><input name="username" type="text" value="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input name="password" type="password" id="password"></td>

Here is checkuser.php


include 'db.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
$roomID = 961;
if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
include 'login_form.html';
exit();
}
// Convert password to md5 hash
$password = md5($password);

// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
session_register('email_address');
$_SESSION['email_address'] = $email_address;

mysql_query("UPDATE users SET last_login=now() WHERE userid='$userid'");

header("Location: test.htm?name=$username");

}
} else {
echo "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />
Please try again!<br />";
include 'login_form.html';
}

?>

All i want is to pass the variables from checkuser.php into the following javascript for the voicechat test.htm i only need to pass 2 variables the $username and the $roomID


<!--Begining of Voice4web Script--><script>
var roomID = 961;
var width = 600;
var height = 360;
var name = document.open('checkuser.php?username');
var mode = 1;
var welcomeMessage = "Baxerben bo chati KurdishVoice";
var optimizeLatency = 1;
var invisible = 1;
var userIcon = 0;
var privateMessage = 2;
var listBgColor = "FFF4FF";


As you can see the problem is with the variables $roomID which should not be a constant and the variable name in the javascript which doesnt accept any $username from the checkuser.php always returns null. The javascript doesnt accept
var name = document.open('checkuser.php?username');

I would appreciate any help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum