dongqianzhan8325 2014-09-15 03:56
浏览 42
已采纳

如何传递HTML / PHP按钮来执行MYSQL查询

Hi guys sorry if my previous questions isn't clear enough, but it came to my senses that my real problem is I can't pass the button click event to execute MYSQL query.

Here is my button that supposed to be when clicked is to execute the query

<form action="invoice.php" method="post">
<input type='submit' name='hehe' />
</form>

Then consider I have established a database connection, here is the code i want to do the trick but it does nothing when the hehe button is clicked

if(isset($_POST['hehe'])){
    $result=mysql_query("   
            SELECT a.id, a.name, s.descc, a.phone, a.start, a.end, a.price
            from wp_app_appointments a 
            LEFT JOIN wp_app_services s 
            ON a.id=s.id
            WHERE a.status ='confirmed'
            order by a.name 
            ");
}

Then I want it to display here.

while($test = mysql_fetch_array($result))

                {   
                if (mysql_num_rows($result)!=0)
                    {
                    $id = $test['id'];  
                    echo "<tr align='center'>"; 
                    /*echo"<td><font color='black'>" .$test['id']."</font></td>";*/
                    echo"<td style='width:200px'></td>";
                    echo"<td style='width:500px'>" .$test['name']."</td>";
                    echo"<td style='width:200px'>". $test['descc']. "</td>";
                    echo"<td style='width:200px'>". $test['phone']. "</td>";
                    echo"<td style='width:200px'>". $test['start']. "</td>"; 
                    echo"<td style='width:200px'>". $test['end']. "</td>";  
                    echo"<td style='width:200px'>". $test['price']. "</td>";    
                    echo"<td style='width:200px'> <a href ='print.php.?id=$id' target=_blank >Print</a>";
                    echo"<td style='width:100px'></td>";        
                    echo "</tr>";

                }
                            }

Sorry for the previous questions.

  • 写回答

1条回答 默认 最新

  • drddx3115 2014-09-15 05:33
    关注
    <form action="invoice.php" method="post">
    <input type='submit' name='hehe' />
    </form>
    <?php
    if(isset($_POST['hehe']))
    {
        $result=mysqli_query($con, "   
            SELECT a.id, a.name, s.descc, a.phone, a.start, a.end, a.price
            from wp_app_appointments a 
            LEFT JOIN wp_app_services s 
            ON a.id=s.id
            WHERE a.status ='confirmed'
            order by a.name 
            ");
        if(mysqli_num_rows($result)!=0)
        {       
            while($test = mysqli_fetch_array($result))
            {               
                $id = $test['id'];  
                echo "<tr align='center'>"; 
                echo "<td style='width:200px'></td>";
                echo "<td style='width:500px'>".$test['name']."</td>";
                echo "<td style='width:200px'>". $test['descc']. "</td>";
                echo "<td style='width:200px'>". $test['phone']. "</td>";
                echo "<td style='width:200px'>". $test['start']. "</td>"; 
                echo "<td style='width:200px'>". $test['end']. "</td>";  
                echo "<td style='width:200px'>". $test['price']. "</td>";    
                echo "<td style='width:200px'> <a href ='print.php.?id=$id' target=_blank >Print</a>";
                echo "<td style='width:100px'></td>";        
                echo "</tr>";
            }
        }
    }
    

    *it should be saved as 'invoice.php'

    *db connection should be 'mysqli'

    eg:

    <?php
    $con = mysqli_connect("localhost","my_user","my_password","my_db");
    
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线