在我的网页中,我无法检索mysql的表值并将其显示在html文本框中。当我运行我的网页时,它不会延迟任何值。有人请帮助我。 P.S:我的数据库名称和表名是正确的。
studentsearch.php
<?php
$hostname_localhost ="localhost";
$database_localhost ="mydatabase";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error());
mysql_select_db($database_localhost, $localhost);
$rollno=$_POST['rollno'];
$submit=$_POST['submit'];
if(isset($submit))
{
$query_search = "select * from student where srollno='$rollno'";
$rowval = mysql_fetch_array($query_search);
$sname= $rowval['sname'];
$srollno= $rowval['srollno'];
$email= $rowval['email'];
$dept= $rowval['dept'];
$phoneno= $rowval['phoneno'];
}
?>
<html>
<head>
<style>
@import url(http://fonts.googleapis.com/css?family=Exo:100,200,400);
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:700,400,300);
body{
margin: 0;
padding: 0;
background: #fff;
color: #fff;
font-family: Arial;
font-size: 12px;
}
.body{
position: absolute;
top: -20px;
left: -20px;
right: -40px;
bottom: -40px;
width: auto;
height: auto;
background-image: url(images/signinback.png);
background-size: cover;
-webkit-filter: blur(5px);
z-index: 0;
}
.grad{
position: absolute;
top: -20px;
left: -20px;
right: -40px;
bottom: -40px;
width: auto;
height: auto;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,0.65))); /* Chrome,Safari4+ */
z-index: 1;
opacity: 0.7;
}
h3 {
margin: 0 15px 20px;
border-bottom: 2px solid;
padding: 5px 10px 5px 0;
font-size: 3.1em;
}
.two{
position: absolute;
top: calc(50% - 75px);
left: calc(50% - 50px);
height: 450px;
width: 650px;
padding: 10px;
z-index: 2;
margin: 0 0 15px 0;
border : none;
}
label {
display: inline-block;
width: 25%;
text-align: right;
margin: 10px
}
.button {
font-size: 1em;
border-radius: 8px;
padding: 10px;
border: 1px solid #59B969;
box-shadow: 0 1px 0 0 #60BD49 inset;
}
</style>
</head>
<body background="webback.png">
<div class="body"></div>
<div class="grad"></div>
<div class="two">
<div class="register">
<h3>STUDENT SEARCH</h3>
<form method="post" name="studentsearch" onsubmit="val();">
<div>
<label for="rollno">Enter student rollno</label>
<input type="text" name="rollno" >
</div>
<div>
<input type="submit" value="submit" name="submit"/>
</div>
<div>
<label for="sname">Student Name</label>
<input type="text" name="sname" value="<?php echo $rowval['sname']; ?>">
</div>
<div>
<label for="srollno">Student Roll Number:</label>
<input type="text" name="srollno" value="<?php echo $rowval['srollno']; ?>">
</div>
<div>
<label for="email">Student Email Id:</label>
<input type="text" name="email" value="<?php echo $rowval['email']; ?>">
</div>
<div>
<label for="dept">Department</label>
<input type="text" name="dept" value="<?php echo $rowval['dept']; ?>">
</div>
<div>
<label for="phoneno">Phone Number</label>
<input type="text" name="phoneno" value="<?php echo $rowval['phoneno']; ?>">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:-1)
您使用mysql_fetch_array并将字符串作为参数。 你需要这样的smth:
$sql = "select * from student where srollno='$rollno'";
$query = mysql_query($sql);
$value = mysql_fetch_array($query);
由于documentaion,参数必须是mysql_query
返回的资源但我强烈建议你使用mysqli或pdo。例如mysqli:
$query = "select * from student where srollno='$rollno'";
$result = $mysqli->query($query);
$row = $result->fetch_array();