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

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

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by nav33n
0

1. You forgot mysql_query in

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

2.

<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 ?

0

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.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.