Here's my form
<form id="place-bid" action="placebid.php?placeBidProductId='.$row['product_id'].'" method="post" >
Your Bid:<br>
<input type="text" placeholder="$$$" name="money">
<input type="Submit" class="button_bid" name="submit" value="Place Bid">
<input type=hidden id='rowid' value=".row['product_id']." name='row_id'>
</form>
and here is my placebid.php
<?php
// $product_id=$_GET['placeBidProductId'];
$product_id=$_POST['row_id'];
echo " Id Produs : ".$product_id;
?>
My problem: I can't get the value from $row['product_id'], it will only echo the string "$row['product_id'] .$product_id;"
I'm guessing that before you are outputting that form you are doing some sort of query of a database. If that is the case then you likely want to change this line
<input type=hidden id='rowid' value=".row['product_id']." name='row_id'>
to
<input type=hidden id='rowid' value="<?php echo row['product_id'];>" name='row_id'>
Use print_r($_POST) for all form post value on form action page i.e. placebid.php. it will show you all value in form. Then make you business logic accordingly.
Related
My question is how to check which form was submitted if I have 2 different forms with the same name, and I can't change the name.
For example I have 2 forms and 2 php scripts that evaluate them:
<form action=mypage.php method=post>
<input type=text name=name>
<input type=submit name=ok value=ok>
</form>
<?php
if(isset($_POST['ok'])) {
$name=$_POST['name'];
}
?>
<form action=mypage.php method=post>
<input type=text name=pass>
<input type=submit name=ok value=ok>
</form>
<?php
if(isset($_POST['ok'])) { // <- here is wrong
$pass=$_POST['pass]']; // this code is not executing
}
?>
How I can differentiate these two submits without changing their names?
P.S I can't bring the (Forms) together.
One solution is to add a hidden input on both forms:
<input type="hidden" name="form1" value="name" />
and:
<input type="hidden" name="form2" value="pass" />
Then to check which one has been submitted:
if(isset($_POST['ok']) && isset($_POST['form1'])){
// For the first form
}
And:
if(isset($_POST['ok']) && isset($_POST['form2'])){
// For the second form
}
BEFORE hitting the submit button on a form, I need to send form variables and their values into a php serialized array (name=>value). And then upon post, I need to pass the array to a php function called modify($vararray). For example:
<form action = "someaction.php" method="post"/>
<input type="text" name="var1" id="var1" <br>
<input type="text" name="var2" id="var2" <br>
<?php
(DO SOMETHING HERE TO CREATE A PHP SERIALIZED ARRAY OF NAME=>VALUE INTO $VARARRAY OF ALL PREVIOUS INPUT VARIABLES ABOVE)
echo "input type=\"hidden\" name=\"modvar" id=\"modvar\" value=\"" . modify($vararray) . "\">\n";
?>
<input type="submit" name="submit" value="Submit"/>
</form>
Any suggestions?
You should use JQuery.serializeArray() for this here you can find an example:
URL: .serializeArray()
I hope this helps!
My question is how do I call input value of user selected which has show by php code from another php.
Normal simple way we get the input this way
$calendar_id_val = $_GET['calendar_id'];
and now it is not working:
For example Show.php, I have one form which show the values from Database and show the result with php variable with While Loop.
<input name="calendar_id" value="<?php echo $calendar_id;?>">
and when user is submit that form I will carry these user selected value and perform insert.php
While you are doing echo in the input use echo $calendar_id_val
You should use form like,
<form action="insert.php" method="get">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>"/>
<input type="submit" name="submit_id" value="Insert"/>
</form>
Insert.php
echo $calendar_id_val = $_GET['calendar_id'];
Does this answer your question?
<form action="insert.php" method="GET">
<input name="calendar_id" value="<?php echo $calendar_id;?>">
</form>
If you want to redirect the user back to show.php, add this to the end of your insert.php script
header('Location: show.php');
exit();
I suggest $_POST var like this:
<form action="insert.php" method="POST">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>" />
<input type="submit" name="submit" value="Submit" />
</form>
insert.php file:
echo $calendar_id = $_POST['calendar_id'];
I have 3 textfields and only one submit button to send all the data of the textfield at once. But how do I send the data of all three textfields at once in php?
<form>
for($x=0;$x<3;$x++){
<input type="text" name="name">
}
<input type="submit" name="submit">
</form>
Now I have a three fields inside a for loop and I have to extract data from all of them using single submit button.So how can I do that?
Using the 'name' attribute on an input allows you to do this for example
<form action='submit.php' method='post'>
<input type='text' name='one'></input>
<input type='text' name='two'></input>
<input type='text' name='three'></input>
<input type='submit' name='submit' value='Submit!' />
</form>
and in your PHP you would do something like this
<?php
if(isset($_POST['submit'])){
$inputOne = $_POST['one'];
$inputTwo = $_POST['two'];
$inputThree = $_POST['three'];
//Do whatever you want with them
}
?>
There are better ways of doing this, but this is probably the simplest to understand
If you want all the inputs to have the same name do this
<input type='text' name='textinput[]'></input>
Use that instead and loop through all of the inputs like so
<?php
foreach($_POST['textinput'] as $input){
//do something with $input
}
?>
You put them all inside the same <form> and make sure they have different values for the name attributes (or that the values end in []).
I believe what you are looking for is this Note the [ ] behind the name field
<form>
for($x=0;$x<3;$x++) {
<input type="text" name="name[]" />
}
<input type="submit" name="submit" />
</form>
Then to retrieve the values
$names = $_POST['name'];
foreach( $names as $name ) {
print $name;
}
my php configuration on server are showing i can post variables to maximum size upto 8MB , thats enough .. but how to check for number of variables , sever is running ubuntu 4.4 , php .
i have a page which takes students marks and send them to a action page , but on action page doing echo for the post variables nothing is being displayed , where are doing an echo "hello"; this shows ...
this is the page which sends the variables
<form name="frm" action="marklistI.php" method="POST" class="" >
<?php $tb->displayTable() ?>
<div class="mainframe">
<input type="hidden" name="batch" value="<?php print $_GET['batch']; ?>"/>
<input type="hidden" name="sem" value="<?php print $_GET['sem']; ?>" />
<input type="hidden" name="chance" value="<?php print $_GET['chance']; ?>"/>
<input name="submit" type="submit" class="hide" value="Save"/>
<input type="hidden" name="url" value="<?php print $_SERVER['REQUEST_URI']; ?>"/>
</div>
</form>
and this are the variables are coming to action page .. but on echo they are not showing any value .
$dept =$_COOKIE['dept'];
$join=$_POST['batch'];
$type='e';
$sem=$_POST['sem'];
$chance=$_POST['chance'];
try placing this code on your action page:
if (isset($_GET)) {
echo "<h3>GET METHOD</h3>";
var_dump($_GET);
}
if (isset($_POST)) {
echo "<h3>POST METHOD</h3>";
var_dump($_POST);
}
if (isset($_COOKIE)) {
echo "<h3>COOKIE METHOD</h3>";
var_dump($_COOKIE);
}
See which method returns your variables and use it, otherwise, you are not filling any values on the form.
this is your code:
<form name="frm" action="marklistI.php" method="POST" class="" >
<?php $tb->displayTable(); ?>
<div class="mainframe"> <input type="hidden" name="batch" value="<?php print $_GET['batch']; ?>"/>
<input type="hidden" name="sem" value="<?php print $_GET['sem']; ?>" />
<input type="hidden" name="chance" value="<?php print $_GET['chance']; ?>"/>
<input name="submit" type="submit" class="hide" value="Save"/>
<input type="hidden" name="url" value="<?php print $_SERVER['REQUEST_URI']; ?>"/>
</div>
</form>
One possible reason for your issue:
You use "_GET[]" variables here but the form is POST.
GET and POST are two different methods to send data, GET is in the URL path (a=&b=&c=) while POST is hidden in the HTML headers.
So make sure you read those results as "$_POST['name']" and not GET.
I suggest this in the "receiving script" for debugging:
var_dump($_GET);
var_dump($_POST);
And in your browser use Chrome or Firefox + Firebug and Press "f12".
In that debugger you can catch the POST when you click the button and you can look which variables were sent.
That should help you debug your issue fast.
One other suggestion, I personally would write the code less "mixed".
It makes it hard to read and hard to modify.
Why not like this:
<?php
echo "
<form name='frm' action='marklistI.php' method='POST' class='' >".
$tb->displayTable().
"<div class='mainframe'>
<input type='hidden' name='batch' value='$_GET[batch]'/>
<input type='hidden' name='sem' value='$_GET[sem]' />
<input type='hidden' name='chance' value='$_GET[chance]'/>
<input name='submit' type='submit' class='hide' value='Save'/>
<input type='hidden' name='url' value='$_SERVER[REQUEST_URI]'/>
</div>
</form> ";
?>
My guess for your problem is that those values in the formular are actually empty, that's why you don't receive anything.