I am trying to carry a variable over to disable.php which will then update a row in the database, all of this is within a wordpress plugin I am building. I cannot see why this won't work.
Heres my form
<form method='post' action='".plugins_url()."/myremovalsquote/inc/disable.php''>
<input type='submit' name='".$_SESSION['id'] = $active_partner->partner_id."' class='button-primary' id='disable' value='Disable'/>
</form>
Heres my /disable.php
global $wpdb;
$id = $_SESSION["id"];
$wpdb->query("UPDATE partners SET active='no' WHERE partner_id='".$id."'");
header("Location: http://www.website.com/wp-admin/admin.php?page=my-plugin-settings");
This is the error I am getting, it seems that the variable from the session isn't being carried over to disable.php.
In addition to my comment, you could either use a hidden input field or store the values to be read and sent in the session alltogether. For the first solution:
<form method='post' action='/myremovalsquote/inc/disable.php'>
<input type="hidden" name="id_to_be_disabled" value="<?= $active_partner->partner_id; ?>">
<input type='submit' class='button-primary' id='disable' value='Disable'/>
</form>
For the second solution just invoke the session with session_start(); and store the value in it. No need to fiddle around with the submit button name.
You have some errors in your form with name and value. Try this:
<form method='post' action='".plugins_url()."/myremovalsquote/inc/disable.php"'>
<input type='submit' name='id' value='" . $active_partner->partner_id."' class='button-primary' id='disable' value='Disable'/>
</form>
And I also would prefer a hidden field here.
put session_start() on your /disable.php
Related
I created a form which asks for username and password for registration purposes and I sent the data to same page using action="" and checking for $_POST variables, but data is not being passed through this method. When I print $POST array by changing condition to true and reloading the page , the POST array is empty and also I can see the variables passed as POST in URL.Can somebody explain whats the problem?
Code:
<!DOCTYPE html>
<html>
<?php
if(isset($_POST['user']))
{
echo "Data coming";
die();
}
else {
?>
<form method="POST" enctype="multiform/form-data" action="">
<b> Username: </b><input type='text' name='user'> <br> <br><br>
<b> Password:</b> <input type='password' name='pass'><br> <br>
<input type='submit' value="Submit">
</form>
<?php
}
?>
</html>
You have to give the name to submit button also.
<input type='submit' name="Submit" value="Submit">
You are checking the index 'Submit' in $_POST and the submitted form is take the value with the name of input type. So you have to given the name to submit button also like above.
You are checking in your if isset for a post named:
$_POST['Submit']
Your submit button doesn't have
name=Submit
As a test to see what you are sending for debug purposes, try putting this in your code, it will help you self-debug:
print_r($_REQUEST);
"input type='submit' name="Submit" ...
Change to this.
$_POST['Submit']
looks for a resource with the name of Submit when you reload the page, as in your code there is no resource with the name of Submit, the if statement returns false and the control switches back to the else part.
Give a name to the submit button and use the same name in the post varibale option.
I am trying to pass input tag value to the another page to simply multiply the value of qty with price and return the updated price.The problem is when i pass the value of qty with get method it passes the value of qty only but does not pass another values.
cart.php
echo" <form method='get' name='form1' action='update_cart.php?id={$id}&name={$name}&price={$price}&qty=$_GET['qty']'>";//the problem comes here.
echo"<input type='number' name='qty' max='10'>
<input type='submit' value='update'></form>";
update_cart.php
$id = isset($_GET['id']) ? $_GET['id'] : "";
$name = isset($_GET['name']) ? $_GET['name'] : "";
$qty=isset($_GET['qty'])? $_GET['qty']: "";
$price=isset($_GET['price'])? $_GET['price']: "";
$price=$price*$qty;
header('Location: cart.php?action=quantity_updated&id=' . $id . '&name=' . $name . '&price='.$price . '&qty='.$qty);
when i click on update button after giving qty a value it shows something like this.
http://localhost/abc/cart.php?action=quantity_updated&id=&name=&price=0&qty=2
form method="get" passes variables automatically.
You do (and can) not need to append query string to the action attribute.
You do however need to represent those data in your form, if with <input type="hidden" name="qty" value="<?=$qty?>" /> style.
if you want pass some values , you can choose 2 way for it :
you can use the input with hidden type in you form.
if you use hidden type input you can use data just on one page.
<form method='get' action='?????'>
<input type='hidden' name='?????' value='?????'>
<input type='hidden' name='?????' value='?????'>
....
...
..
<input type='number' name='qty' max='10'/>
<input type='submit' value='submit'/>
</form>
you can use session for save data and use it in another page.
if you use session, you can use data in all php pages.
on page 1:
<?php
session_start();
$_SESSION['name']='value';
?>
on page 2:
<?php
session_start();
echo $_SESSION['name']; // value
?>
Your syntax for this line contains errors.
echo" <form method='get' name='form1' action='update_cart.php?id={$id}&name={$name}&price={$price}&qty=$_GET['qty']'>";
Change it to...
echo" <form method='get' name='form1' action='update_cart.php?id=".$id."&name=".$name."&price=".$price."&qty=".$_GET['qty']."'>";
My website involves a user submitting data over several pages of forms. I can pass data submitted on one page straight to the next page, but how do I go about sending it to pages after that? Here's a very simplified version of what I'm doing.
Page 1:
<?php
echo "<form action='page2.php' method='post'>
Please enter your name: <input type='text' name='Name'/>
<input type='submit' value='Submit'/></form>";
?>
Page 2:
<?php
$name=$_POST["Name"];
echo "Hello $name!<br/>
<form action='page3.php' method='post'>
Please enter your request: <input type='text' name='Req'/>
<input type='submit' value='Submit'/></form>";
?>
Page 3:
<?php
echo "Thank you for your request, $name!";
?>
The final page is supposed to display the user's name, but obviously it won't work because I haven't passed that variable to the page. I can't have all data submitted on the same page for complicated reasons so I need to have everything split up. So how can I get this variable and others to carry over?
Use sessions:
session_start(); on every page
$_SESSION['name'] = $_POST['name'];
then on page3 you can echo $_SESSION['name']
You could store the data in a cookie on the user's client, which is abstracted into the concept of a session. See PHP session management.
if you don't want cookies or sessions:
use a hidden input field in second page and initialize the variable by posting it like:
page2----
$name=$_POST['name']; /// from page one
<form method="post" action="page3.php">
<input type="text" name="req">
<input type="hidden" name="holdname" value="<? echo "$name"?>">
////////you can start by making the field visible and see if it holds the value
</form>
page3----
$name=$_POST['holdname']; ////post the form in page 2
$req=$_POST['req']; ///// and the other field
echo "$name, Your name was successfully passed through 3 pages";
As mentioned by others, saving the data in SESSION is probably your best bet.
Alternatly you could add the data to a hidden field, to post it along:
page2:
<input type="hidden" name="username" value="<?php echo $name;?>"/>
page3
echo "hello $_POST['username'};
You can create sessions, and use posts. You could also use $_GET to get variables from the URL.
Remember, if you aren't using prepared statements, make sure you escape all user input...
Use SESSION variable or hidden input field
This is my workaround of this problem: instead of manually typing in hidden input fields, I just go foreach over $_POST:
foreach ($_POST as $key => $value) {
echo '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
}
Hope this helps those with lots of fields in $_POST :)
i have a page where i am getting the ques id and insert it in the database for that i am doing
url: */faq/faq_question_sol.php?ques= 62*
this ( $selected_ques= ($_GET['ques']); ) is working properly in the *faq_question_sol.php* but the *answer_submit_process.php* does not recognize it
my form
<form id="post-form" class="post-form" method="POST" action="answer_submit_process.php">
<input id="submit-button" type="submit" tabindex="120" name="submitbutton" value="Post Your Answer" />
</form>
and the *answer_submit_process.php* is
if(isset($_POST['submitbutton'])){
$userid = $_SESSION['userid']; // i have already started the session
$selected_ques= ($_GET['ques']);
$content = $_POST["content"] ;
$query="INSERT INTO `formanswer`( `user_id`,`questionid`,`content` ) VALUES ('{$userid}','{$selected_ques}','{$my_html}' ) ";
$result=mysql_query($query);
}
Quickest solution would be saving the value of $_GET['ques'] on a hidden field of the form and thus make it accessible in answer_submit_process.php.
Something like this:
if (isset($_GET['ques'])){
echo '<input type="hidden" name="ques" value="'.$_GET['ques'].'">';
}
And in answer_submit_process page the value could easily accessed by $_POST['ques']..
If you are sending via a form POST, then the variable from which you can get data is $_POST instead of $_GET.
Anyway, i wasn´t able to find any field relating to the ques variable on your form, where are they?
Add <input type="hidden" name="ques" value="<?php echo $_GET['ques'] ?>"/> to your form to temporarily store the variable, and then use the variable $_POST['ques'] in place of $_GET['ques'] in the processing page.
Alternatively, you could change the form action to answer_submit_process.php?ques=<?php echo $_GET['ques']; ?>.
I have a php page with the following:
echo "<form method='post'><input type='hidden' id='memberIdd' name='memberIdd' value=" . $memberId . "></form>";
Now I created another php page and want to grab the value of this hidden field and place it into another variable. How can I do this? I tried using this for my second php page:
$member = $_POST['memberIdd'];
But I just keep getting "undefined" for $member.
Thanks
I think your problem is that you did not set the right action in the form and you also should have a submit button. Thus, your form should look like:
echo '<form action="url-to-the-second-page.php" method="post">';
echo '<input type="hidden" id="memberIdd" name="memberIdd" value="' . $memberId . '">';
echo '<input type="submit" name="submit" value="submit" />';
echo '</form>';
<form method='post' action='secondpage.php'>
http://www.w3.org/TR/html4/interact/forms.html#h-17.1
If you don't write the action then the posted data goes to the same page where you were.
And by the way, the variable $memberId (the one in your question) at the firstpage.php should be defined. In other case it will prompt error message.
Edit: It will better for you to use HTML codes out of PHP.
That's a hidden form field, but you've no submit button. The value won't appear in the second page unless you specify it as the form's action (i.e. where the form should be submitted to), and also submit the form. e.g.
echo "<form action='page2.php' method='post'>
<input type='hidden' id='memberIdd' name='memberIdd' value=" . $memberId . ">
<input type="submit" value="Go to page 2">
</form>";
Alternatively, you could store the value as a session variable.