Iam working with my project and i had no time
Iam working with a php, mysql program, In this program I have combobox for student_id
I need onchange of this combo to execute another select statement (for example select name from student where studentid=...) and put the name in a text box
my problem is as follows:
onchange I need to call a javascript function and inside it run a php that selects from table where studentid=(the value of the combo). how can I do that, that is passing javascript variables or values to php
I tried to make submit to the same form but it is not working this is my php file:
add1.php
<?php
$db = mysql_connect('localhost','root', 'password');
mysql_select_db ("collab1",$db);
$sql=mysql_query("select Id from student",$db);
?>
<html>
<title>New Violation</title>
<body>
<form name='form1' method='post' action='add1.php'>
Student Id:<select name='sid' onchange='getname()'>
<?while ($row = mysql_fetch_array($sql, MYSQL_NUM)) {?>
<option value='<?= $row[0]?>'><?= $row[0]?>
<?
}?>
</select>
<br>Name:<input name='sname' type='text'/>
<input type='submit' value='Add New Violation'/>
</form>
<script language='javascript'>
function getname(){
{
form1.submit();
<?
if(isset($POST["sid"]))
{
$sql=mysql_query("select * fom student where student_id=".$POST["sid"],$db);
$row=mysql_fetch_row($sql);
}
?>
form1.sname.value=<?=$row["sname"]?>;
}
</script>