I have a form with a button that preforms multiple queries on a database.

Problem is only one of those queries are preformed when the button is clicked.

If I break them up into seperate buttons they both work.

This means 1 button = 1 query?

That dosent sound right.

Thanks for the help, Regards X

Recommended Answers

All 14 Replies

You can run multiple queries.

if(isset($_POST['submit'])) {
//query 1
//query 2
//query 3 .....
<form method="post">
<input type="submit" name="submit" value="submit">


I am using a swtich statement for my buttons, is that making a difference (also the isset function just test if a variable exists?)?

The queries I run are on the same two different tables but the queries I run are:
table1 select
table1 update
table2 select
table2 update

If there is nothing 'tricky' I should be aware of before I start I might just reprogram the code as I have done what you have stated above it still not working :(

Yep. isset checks if a variable exists and is set. Can you post your code so that we can see where you are going wrong ?

Can you post your code.

Just tried posting it way too big and long.

Cut setup from my code below:

switch('button') {
 case 'update':
  header('refresh: 0; url=updating.php');
  for($i=0; $i<$numberOfRows; $i++) {
   $query = "update table set number = '$i' ";   
   $query_default = "update table set number = '0' " 
   while ($fetch = mysql_fetch_assoc($queryFetch)) {
   for($i=0; $i<$numberOfRows; $i++) {
    $query = "update table set number = '$i' ";   

This is a brokern down version of my code but the same setup.
The //// is where I made it 2 seperate buttons and it worked but together they dont.

Thanks, Regards X

Try commenting header('refresh: 0; url=updating.php'); and see if it works.

Ahh you reminded me now nav!!!

Correct worked when I commented out the header() BUT now obviously I have no refresh which I need.

If you remember months ago nav I was asking about refreshing, this was why.

So any idea of a solution my php guru :D?

Thanks Again, Regards X

why do you need to refresh

Why don't you refresh after you are done with all the processing ? Why do you want to refresh anyway ? I don't think it will work that way..

Dosent the header command have to be the first line?

Anyways even if I put it after still the same result - 2 click to view update.

Hence why I want to refresh, as I want to see the updates that have taken place.

So I gather there has to be a solution, I cant believe that after a query has taken place it is not possible to refresh page. Seems to newbie for php not to be able to do it.


yeah you can perform the refresh after the query is performed.

you can use the header function anywhere in your php code. you need to make sure no headers have been sent before it though.

We cant use the header and the query together :(

i don't see why not, i do it all the time in my applications.

Ya I also do but in this case, you cant.

Maybe its because its a refresher header.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.