0

My article title is a bit misleading but since it is my primary concern so I made that my title.
Anyway,
this is the problem
I have form and it generates a list of people that is needed to be scheduled.
this is (more-or-less) the code.

<?php 
    $strQuery = "your query";
    $result = mysql_query($strQuery);
    $x=1;
    while($arrResult = mysql_fetch_array($result))
    {
    ?>
    <div class="appl_row">
    <p><?php echo $arrResult['name_info']; ?></p>
    <input type="text" id="txtDate<?php echo $x ?>" name="txtDate<?php echo $x ?>" />
    <input type="submit" id="btnsched<?php echo $x; ?>" name="btnsched<?php echo $x; ?>" />
    </div>
    <?php 
    $x++;
    } ?>

I put the $x variable since the id needs to be unique and the name to be unique.
so if it generates a 20 records from the database.

so in source you will see btnsched1, btnsched2, so on... etc.
so how will I know that I clicked btnsched1? and how will I know that I am getting the value of txtDate1

if you use $_POST['btnsched'] it will just fire an error since you do not have btnsched on the first place.

Did I miss something or do you have suggestion to how my problem could be implemented in a different way?
Thanks For the Reply guys.

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by adam.adamski.96155
0

@php_noob

I have form and it generates a list of people that is needed to be scheduled.
Did I miss something or do you have suggestion to how my problem could be implemented in a different way?

Can you post the whole code? It's very confusing. My question why did you post this code? I know you explain it but it doesn't really help at all base on that little code?

0
 <input type="text" id="<?php echo 'txtDate'.$x; ?>" name="<?php echo 'txtDate'.$x; ?>" />
<input type="submit" id="<?php echo 'btnsched'.$x; ?>" name="<?php echo 'btnsched'.$x; ?>" />

I hope this fixes it

0

I answered the same question yesterday so I can just copy and paste :D

You need to make sure all your form elements are contained within a form declaration:

<form action="page_that_will_process_form.php" method="post">
<input type="text"... />
<input type="button"... />
</form>

Make sure each input has a unique name.
<input name="unique_name"... />

Then on the page that will process the form (it can be the same page):

<?php
if( isset($_POST['unique_name']) ){// isset() stops the undefined error.
    if(isset($_POST['button_one'])){
    // Button one was clicked, do appropriate stuff
    }
    if(isset($_POST['button_two'])){
    // Button two was clicked, do appropriate stuff
    }
}
?>

If the button was not clcked, it will not exist as a $_POST variable.

Edited by adam.adamski.96155

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.