【问题标题】:Retrieving mysql table values in html textbox using php使用php在html文本框中检索mysql表值
【发布时间】:2015-05-22 05:12:28
【问题描述】:

在我的网页中,我无法检索 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>

【问题讨论】:

    标签: php html mysql css


    【解决方案1】:

    您正在使用带有字符串作为参数的mysql_fetch_array。 你需要这样的东西:

    $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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多