$hostname = "localhost";
$username = "hi";
$password = "bye";
$dbid = "jesus";
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$result=("SELECT name FROM lydia WHERE nam='$name1'");
while($myrow = mysql_fetch_array($result))
echo $first;
<script type="text/javascript">
function win()
var c='<?php echo $first; ?>';
<form name="form1" method="get" action="<?php echo $PHP_SELF;?>" onSubmit="javascript:win();">
NAME<input name="text" name="name1">
<input type="submit" value="submit">

in this code i want to alert the $first variable.javascript executed before php.is there any solution alert the variable in script.

1. You forgot mysql_query in

$result=("SELECT name FROM lydia WHERE nam='$name1'");


<input name="text" name="name1">

Should have been input type="text".
And, at the first run, ie., when the script is executed for the 1st time, the query will not output anything since $_REQUEST is empty.(or it will output the rows which has an empty nam field). Why not have form method as Post ?

sorry .those two lines which you mentioned are wright in my code,i typed it wrongly in the forum.sorry.i want to know exact error in this code.

Can you post your original code ?

Edit: Btw, for the first execution, $first will be null.. Thats the reason it shows an empty alert.

This article has been dead for over six months. Start a new discussion instead.