输入文本值不从PHP中的数据库获取数据

时间:2016-03-30 07:01:45

标签: php sql-server

enter image description here

当我单击提交按钮时,应显示数据库中的数据,而是显示空表。我不知道出了什么问题。当我在sql-server上执行SQL时它工作正常,但是在这里它不会获取结果并显示它们。

这是要显示的预期结果..请问有谁可以帮助我? enter image description here

<body>
<form id="FromID" name="FromID" method="post">
<br><br>
<div align="center" style="font-family:Rockwell,Courier Bold,sans-serif; font-size:22px;font-weight:bold;">SMS Status </div>
<br><br>
<table style="border: 1px solid black" border="1" cellpadding="0"  cellspacing="0" align="center" width="25%" class="style">        
        <tr>
            <td>Group Name</td>
            <td><input type="text" name="grp" id="grp"></td>                
        </tr>
        <tr>
            <td>Subscribtion Number</td>
            <td><input type="text" name="num" id="num"></td>                
        </tr>   
        <tr>
        <td colspan ="2" align="center">
        <input type="submit" name="Submit" id="Submit" value="Submit" />
        </td>
        </tr>       
</table>
<br>

<?php
if(isset($_POST['Submit']))
{
$group=$_POST['grp'];
$subscribe=$_POST['num'];

if(!empty($group) && !empty($subscribe))
{
$q= "select send_date_d,grp_name_vc,subr_no_i,send_type_vc,result_vc,brn_id_vc,subr_mobile_vc,subr_name_vc  from tblsmsstatus
where grp_name_vc='$group' and subr_no_i='$subscribe'";
}
else
{
echo "Enter valid Group Name and Subscribtion number";  
}
$result = mysql_query($q);
  echo $q;
  echo "<table class='TFtable' border ='1' align ='center' cellpadding='1' cellspacing='1'  width='800' bgcolor='#FFFFFF' style='border:1px solid #0080FF;' >";
  echo "<tr><th style='background:#58ACFA;'>S.No</th>
          <th style='background:#58ACFA;'>Date</th>
          <th style='background:#58ACFA;'>Name</th>
          <th style='background:#58ACFA;'>Group Name</th>
          <th style='background:#58ACFA;'>Subscribtion Number</th>
          <th style='background:#58ACFA;'>Send Type</th>
          <th style='background:#58ACFA;'>Result</th>
          <th style='background:#58ACFA;'>Branch</th>
          <th style='background:#58ACFA;'>Mobile</th><tr>"; 

          $i=1;

        while($row=mssql_fetch_assoc($result))
        {
            ?>
            <tr bgcolor="#CEF6F5">
                <td align="center" style="padding-right:px;text-decoration:none;">
                    <?php echo $i;?>
                </td>               
                <td align="center"  style="padding-left:10px;text-decoration:none;">

                    <?php echo $row['send_date_d'];?>
                </td>
                <td align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['subr_name_vc'];?>
                </td>
                 <td align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['grp_name_vc'];?>
                </td>
                <td  align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['subr_no_i'];?>
                </td>
                 <td align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['send_type_vc'];?>
                </td>   
                 <td align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['result_vc'];?>
                </td>
                <td align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['brn_id_vc'];?>
                </td>
                <td align="center"  style="padding-left:10px;text-decoration:none;">
                    <?php echo $row['subr_mobile_vc'];?>
                </td>           
            </tr>               
         <?php
          $i++;
          }            
        }
          ?>
          </table>

          </form>
</body>

`

2 个答案:

答案 0 :(得分:1)

您使用了两种不同的数据库库函数。您正在使用$result = mysql_query($q);执行查询,而在另一部分中,您正在从函数mssql_fetch_assoc()执行数据;

使用mssql_query();

答案 1 :(得分:0)

如果这是完整的代码,那么错误就是你将php连接到mssql服务器,使用下面的代码连接然后你可以运行查询。

$server = 'KALLESPC\SQLEXPRESS'; //your server name

// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi'); //server authentication and db name

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}else{

     //all the codes goes here
}