php - Grabbing data from two HTML forms from the same page -


so i've searched through posts, , i've seen can't use html form within html form. like:

<form method="post" action="x.php">     <input type="..."/>     <form method="post" action="x.php">         <input type="..."/>     </form> </form> 

ok, problem want make different page, contains html code this:

<?php if(isset($_get['vote']) && $_get['vote']=='yes'){     echo 'vote inserted'; }  # gets email value main form $email = isset($_post['email'] : $_post['email'] : null;  #grab infos bd user email, $stmt = $db->prepare('select name,email,vote tbl email=:e'); $stmt->execute(array(':e'=>$email)); while($row = $stmt->fetch(pdo::fetch_obj)){     if($row->vote == 'no'){ # if user didn't voted,         if(isset($_post['vote'])){ # if <a> pressed, update db             $sql = "update tbl set vote='yes' email=:e";             $s = $db->prepare($sql);             $s->execute(array(':e'=>$email));         }     }     ?>     <table>         <tr>             <td>name</td>             <td>email</td>             <td>address</td>             <td>vote</td>         </tr>         <tr>             <td><?php echo $row->name;?></td>             <td><?php echo $row->email;?></td>             <td><?php echo $row->address;?></td>             <td>                 <form method="post" action="" id="second">                     <a href="index.php?vote=yes" name="vote">vote!</a>                  </form>              </td>         </tr>     </table> <?php } // end while() ?> 

then, under <table>, have form:

<form action="" method="post" id="main>     <input type="text" name="email" placeholder="email"><br/>     <input type="submit" value="login" name="submit"/> </form> 

the project electoral campaign, user can 'login' email address, , submit vote. so,

  1. when user requests page, main form pop-up, fill in email, , press submit.
  2. he redirected same page (i'm hiding main form), , table pop-up.
  3. now, user can select favorite candidate, , press on <a> link - vote stored in db, updating vote field from, 'no' 'yes'.

now, prob when <a> link pressed, update in db doesn't take place.

the reason link doesn't update database because form not being submitted. change

<input type="submit" value="vote!"> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -