Я написал функцию на странице HTML.
В этой функции я пытаюсь получить значения из таблицы базы данных MySQL с предложением where
. Этот предоставленный параметр будет исходить из текстового поля. Теперь я хочу вызвать эту функцию с помощью события onclick
кнопки, и результат должен отображаться в текстовых полях веб-страницы. Пожалуйста, укажите в коде, как я могу написать PHP код для этого.
Я пытаюсь выполнить следующее, но это не работает и ничего не показывает.
<?php
function displayclass(){
require("config.php");// calling connection string
$batchid=$_POST["batchid"];// data taken from a combobox1
$sqlbatch = "SELECT Cource,BatchID,Stream, StreamCode FROM table1
WHERE BatchID='".$batchid."'"; // this batchid is supplied from combobox
$resultbatch=$conn->query($sqlbatch) or die($conn);
if(mysqli_num_rows($resultbatch)>0){
while($row=mysqli_fetch_array($resultbatch)){
$cource=$row['Cource'];
$batchid=$row['BatchID'];
$stream=$row['Stream'];
$streamcode=$row['StreamCode'];
}
}
}
?><!-- upto this it OK. no error is found.-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
</head>
<body>
<div id="wb_Form1"
style="position:absolute;left:217px;top:137px;width:470px;height:296px;z-
index:9;">
<form name="Form1" method="post" action="" enctype="multipart/form-data"
id="Form1">
<label for="" id="Label1"
style="position:absolute;left:43px;top:39px;width:92px;height:21px;line-
height:21px;z-index:0;">Select Batch</label>
<label for="" id="Label2"
style="position:absolute;left:43px;top:87px;width:92px;height:21px;line-
height:21px;z-index:1;">Stream</label>
<label for="" id="Label3"
style="position:absolute;left:43px;top:130px;width:92px;height:21px;line-
height:21px;z-index:2;">Cource</label>
<label for="" id="Label4"
style="position:absolute;left:43px;top:173px;width:92px;height:21px;line-
height:21px;z-index:3;">Stream Code</label>
<select name="batchid" size="1" id="batchid" onclick="displayclass()"
style="position:absolute;left:165px;top:39px;width:158px;height:28px;z-
index:4;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="text" id="stream"
style="position:absolute;left:165px;top:88px;width:148px;height:16px;z-index:5;"
name="stream" value="<?php echo $stream; ?>">
<input type="text" id="cource"
style="position:absolute;left:165px;top:133px;width:148px;height:16px;z-
index:6;" name="cource" value="<?php echo $cource; ?>">
<input type="text" id="streamcode"
style="position:absolute;left:165px;top:174px;width:148px;height:16px;z-
index:7;" name="streamcode" value="<?php echo $streamcode; ?>">
<input type="submit" id="show" name="show" value="Show"
style="position:absolute;left:176px;top:221px;width:96px;height:25px;z-
index:8;">
</form>
</div>
</body>
</html>
it shows the following message while loading the page.
<br /><b>Notice</b>: Undefined variable: stream in <b>C:\xampp\htdocs
\collegeproject\test\selectbatch3.php</b> on line <b>35</b><br />
<br /><b>Notice</b>: Undefined variable: cource in <b>C:\xampp\htdocs
\collegeproject\test\selectbatch3.php</b> on line <b>36</b><br />
<br /><b>Notice</b>: Undefined variable: streamcode in <b>C:\xampp\htdocs
\collegeproject\test\selectbatch3.php</b> on line <b>37</b><br />