0

I am trying to save some values into db, on first page i am running some matches and on the the 2nd page i need to save values. on first page only click button is shown to user, when he clicks , the values are stored.

code

<form action="ms_insert.php" method="post">
<input type="submit" value="Claim your daily bonus" name="test">
</form>

How can i submit all the values that are outside the form and send them to the ms_insert.php and process the values.

What i need to achieve it like this.

some values shall be matched , on successful match it will save the enteries into the db.

Here is the exact code that i am using now :

<?php
if ( $thismemberinfo[msurf] >= $msurfclicks ) {
$sql=$Db1->query("INSERT INTO d_bonus VALUES('$userid','0.02',NOW())"); 
echo "success";
}
else
{
echo "wrong";
}
?>
<form action="" method="post">
<input type="hidden" value="123" name="match">
<input type="submit" value="Claim your daily bonus $o.o2" name="claim">
</form>

I want this php code to excute when user click the submit button.

4
  • <input type="hidden" .../>, sessions...? Commented Aug 11, 2014 at 15:33
  • 2
    Why do you need to submit form elements that reside outside the form tag? It's there to contain them. Commented Aug 11, 2014 at 15:37
  • these are not the form elements. I have some conditions that are already outside form, once user clicks the submit button, I need them to store the values in the db, Commented Aug 11, 2014 at 15:40
  • possible duplicate of Php page with html form inside execute php code before form is completed Commented Aug 11, 2014 at 18:10

2 Answers 2

0

There are two ways that I can think of doing this:

  • Simply set the post variable to another value as described here:

    $_POST['text'] = 'another value';
    

    This will override the previous value corresponding to text key of the array. The $_POST is super global associative array and you can change the values like a normal php array.

  • Second would be to use _SESSION tags as described in this post:

    In the first.php:

    $_SESSION['favcolor'] = 'green';
    

    In ms_insert.php:

    echo $_SESSION['favcolor']; // green
    

P.S. You can also use cookies

Additional sources:

Sign up to request clarification or add additional context in comments.

1 Comment

Have a look at this post this might help.
-1

You can use Javascript with a XHR object for example or try to insert your values to store in hidden inputs.

Solution 1 : AJAX, for example :

Your JS (Here with Jquery):

function saveInDb(){

    /* Retrieve your values in your page : */
    var myValue1 = $('#value1Id').val();
    var myValue2 = $('#value2Id').val();

    /*Create a Jquery ajax object : */
    $.ajax({
      type: "POST",
      url: "ms_insert.php",
      data: { "value1": myValue1, "value2": myValue2 }
    }).done(function( msg ) {
        alert( "Data Saved");
    });
}

Your HTML :

<span id="value1Id">My value 1</span>
<span id="value2Id">My value 2</span>
<button onclick=saveInDb()></button>

Solution 2 : the HTML with hidden inputs :

<form action="ms_insert.php" method="post">
   <input type="hidden" value="My value 1" name="value1">
   <input type="hidden" value="My value 2" name="value2">
   <input type="submit" value="Claim your daily bonus" name="test">
</form>

1 Comment

Please show how. The answer as is should be a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.