0

Here is the code for my form:

  <form action = "index.php" method="post"> <!--the form is being submitted to the same page-->
  <button class="btn" name="button" onClick="submit()">Yes</button>
  <button class="btn btn-primary active" name="button" onClick="submit()">No</button>
  </form>

And on the top of my index.php I have the following:

<?php
$refresh = $_POST['button'];
?>

When I echo $refresh after I push the button, all I get is 0. Any idea of what I'm doing wrong?

Thanks in advance!

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by lps
0

@persianprez

1) I can't answer the question because I'm not sure what is in the index.php (code)

2) Do you have a database connected to your FORM?

Edited by LastMitch: grammer

0

I dont have a databse connected to my form, index.php is sending the button data to itself to be used as a variable

0

Based on my understanding, the form is submitted without any values provided.

0

even if I add values like "1" for on and "0" for off, it still always prints 0

0

Your button has no value so it will be empty. 2 things:

  1. Change your buttons to a submit and remove the javascript:

    <input type="submit" class="btn" name="submit_yes" value="Yes" />
    <input type="submit" class="btn btn-primary active" name="submit_no" value="No" />

Then change your PHP to get the value of the submit:

<?php
$refresh = $_POST['submit'];
?>
0

@simplypixie I have think of the way also but as the name of the input is not the same, the post method can't get the value with only one $_post.

If really wish to do it this way, php code would be

if(isset($_POST['submit_yes'])){
    echo $_POST['submit_yes'];
}elseif(isset($_POST['submit_no'])){
    echo $_POST['submit_no'];
}
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.