0

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.

6
  • 1
    sidenote: stop using deprecated mysql_* functions & why use double & single quotes in same HTML ? Commented Sep 15, 2014 at 3:58
  • Have you tried running the mysql code manually and seeing if it actually runs properly? Commented Sep 15, 2014 at 4:02
  • Sorry im just a beginner. What should I use? The mysql_* function you say is the one im using on my search query. and it works perfectly fine. Commented Sep 15, 2014 at 4:02
  • @General_Twyckenham: Yes it do run properly. Commented Sep 15, 2014 at 4:04
  • Use either mysqli or pdo instead of mysql_query. Are you sure the code is being run at all (i.e., echo out a statement if hehe is set) Commented Sep 15, 2014 at 4:06

1 Answer 1

1
<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();
  }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Hey thanks. It works like a charm, im having trouble displaying all the columns but i think i can manage it due to my first code. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.