Najd
Najd

Reputation: 35

2 Formes in one page - second form is working without action

My problem is close to this: PHP: 2 forms different action pages, only 1 form action works

I am making a php page that gets a search value of a student name from form1 and lists the matches students name with a button delete student under each one (form2) Now form 2 action=delete.php is not working.

     <?php   $results = array();
        $results = mysql_fetch_array($raw_results);
        echo ''.$ln.' matches found as following:';

        for($i=0;$i<$ln;$i++){ ?> 

    <ul data-role="listview" data-divider-theme="d" data-inset="false">
     <li data-role="list-divider" role="heading">             
    <?php echo 'StudentName:'; echo (" $results[3] "); ?>
    </li>
     <li data-theme="c">

     <?php echo 'Email:'; echo (" $results[4] "); ?>

    </li></ul>

<?php    echo' <form name="form1" method="post" action="delete.php">  /*here is the problem*/

                            <input type="button" name="delete" class="button red" value="Delete member"> 
                            <input type="hidden" name="id"  value="'. $results[0].'"    > 

    </form> '; ?> 

You might ask why I print form with echo? because I tried this also and it did not work:

  <form name="form1" method="post" action="delete.php"> 

                    <input type="button" name="delete" class="button red" value="Delete member"> 
                    <input type="hidden" name="id"  value="<?php  echo $results['0']; ?>" > 

                  </form>

and this is deletestudent.php

<?php

include ('connect.php');

if (isset($_POST['delete'])) {
$mid=$_POST['id'];
             mysql_query(" DELETE FROM member WHERE (m_id='$mid') "); 
 }

  ?>

Hope the justification is clear, I am ready to write more details if needed

Upvotes: 0

Views: 186

Answers (2)

Elasek
Elasek

Reputation: 123

You are not submitting the form.

<input type="button" name="delete" class="button red" value="Delete member">

should be

<input type="submit" name="delete" class="button red" value="Delete member">

Upvotes: 2

MrAsterisco
MrAsterisco

Reputation: 889

The action attribute of a form is automatically performed only when a Submit button is pressed.

Try to change your code like this:

<input type="submit" name="delete" class="button red" value="Delete member">

The "Submit" button type will automatically trigger the action and should pass the form inputs as post parameters, as expected.

Upvotes: 1

Related Questions