I was wondering if it is possible to use a variable from a form as its own URL... its hard to explain in my opinion, heres an example:
matchmaking.php:
$search_summoner = $_POST['search_summoner'];
echo '<form method="post" action="matchmaking.php?search=' . $search_summoner . '">';
echo '<input type="text" name="search_summoner">';
echo '<input type="submit">';
echo '</form>';
As you can see the action sends it back to matchmaking.php but with a variable from the form which was just submitted. The code above, which I have tried, didn't seem to work; So I wondered if anyone else had any ideas on how to do this...
Thanks for the help in advance
using jquery you could set the action parameter like this (add an ID "search" to the form)
$('input[name="search_summoner"]').on('keyup'function(){
$('form#search').attr('action','matchmaking.php?search='+$(this).val());
});
So, while typing, the action parameter will be extended by every character of the typed search string.
Try this;
<?php
if(isset($_POST['search_summoner']) && $_POST['search_summoner'] != '')
{
$search_summoner = $_POST['search_summoner'];
}
else
{
$search_summoner = "";
}
echo $search_summoner; // This displays your Query
?>
<html>
<body>
<form method="post" action=<?php echo $_SERVER['PHP_SELF']; ?>>
<input type="text" name="search_summoner">
<input type="submit">
</form>
</body>
</html>
If I understand you right, I think you want to do something like this:
$search_summoner = $_POST['search_summoner'];
echo '<form method="post" action="matchmaking.php">';
echo '<input type="hidden" name="search" value="'.$search_summoner.'"/>';
echo '<input type="text" name="search_summoner">';
echo '<input type="submit">';
echo '</form>';
Related
I want to add value of product_id inside database using bidupdate.php.
But everytime i try this. It says Error in connection as explained in die function in php. The value of product_id is not passing. I think there is some error in the value phase. Please check it.
<?php
if(isset($_SESSION['user_id'])){
echo '<form id="myForm" method="POST" action="bidupdate.php">';
echo '<input type="hidden" name="product_id" value = "<?php echo '.$_REQUEST['product_id'].'">';
echo '<button input="submit" name="bid">Bid Now</button>';
echo '</form>';
}
?>
You can't call the value in php close within php. that is possible with html. Use this code
<?php
if(isset($_SESSION['user_id'])){
echo '<form id="myForm" method="POST" action="bidupdate.php">';
echo '<input type="hidden" name="product_id" value = "'.$_REQUEST['product_id'].'">';
echo '<button input="submit" name="bid">Bid Now</button>';
echo '</form>';
}
?>
This is Wrong:
echo '<input type="hidden" name="product_id" value = "<?php echo '.$_REQUEST['product_id'].'">';
You cannot use <?php ?> inside PHP code.
Corrected code:
echo '<input type="hidden" name="product_id" value = "'.$_REQUEST['product_id'].'">';
As the title says
$champion = array();
for($i=1;$i<=$champ_number; $i++){
$champion[$i] = $_POST['champno'.$i];
}
echo '<input type="hidden" name="champion[]" value="'.$champion.'">';
What's the simplest least secure way to POST this variable $champion through POST is?
try to follow this simple format:
E.g. : FORM
<form method="post" action="submit.php">
<?php
$champion=array('hiii','helloooo');
echo '<input type="hidden" name="champion" value="'.htmlspecialchars(json_encode($champion)).'">';
?>
<input type="submit" value="sub">
</form>
your submit.php :
<?php
$champions = json_decode($_POST['champion'], true);
echo $champions[1];// out put helloooo
?>
If you really want to post the entire array, then: serializing your array. http://php.net/manual/de/function.serialize.php
...
$championSerialized = serialize( $champion );
echo '<input type="hidden" name="champion" value="' . $championSerialized . '">';
Retrieving the data is just using $championPost = deserialize( $_POST[ 'champion' ] );
I am trying to make code changing news pages and I am having difficulties.
$_SESSION['page'] doesn't change value and always stays as 1.
Thank you.
<?php
session_start();
if (!isset($_POST['set_page'])) {
$_SESSION['page'] = 1;
}
else {
eval("return '".$_POST['change_page']."';");
}
echo "Page ".$_SESSION['page'];
echo '<form action="test.php" method="post">';
echo '<input type="hidden" name="change_page" value="$_SESSION["page"]++"/>';
echo '<input type="submit" name="set_page" value="Next Page"></form></p>';
?>
Your statement here is wrong ++ operator will work like that change that line like this
echo '<input type="hidden" name="change_page" value="'.$_SESSION["page"]++.'"/>';
and your single quotes, When you embed some variable inside string use double quotes or use concatenation.
I want to retrieve the data from a textbox which I created. Please take look at my code and help me.
<?php
if(isset($_GET['ok']))
{
$a=1;
$n=$_GET['n'];
for($i=0;$i<$n;$i++){
echo '<form action="exa.php" method="get">';
echo '<input type="text" name="kal'.$a.'"/> <br/>';
echo '</form>';
$a++;} $a=1;
for($i=0;$i<$n;$i++)
{
$txtnm="kal".$a;
$kal=$_GET['$txtnm'];
echo $kal;
$a++;
}
}
?>
<html>
<body>
<form action="exa.php" method="get">
<input type="text" name="n"/><br/>
<input type="submit" value="OK" name="ok"/>
</form>
</body>
</html>
Here I am getting an error saying 'undefined index $txtnm'
here i am getting error that undefined index $txtnm ...
$kal=$_GET[$txtnm];
remove the single quotes, you are treating it as constant if you put those single quotes
Try to do like this
echo 'Input '.$a.'<input type="text" name="kal[]"/> <br/>';
and after submitting form the kal array like
print_r($_REQUEST['kal']);
And why you are using get method,without specific need dont use get method while submitting the textarea data,because some of special characters causes your redirect
Remove single quote from $kal=$_GET['$txtnm'] . It should be
$kal=$_GET[$txtnm];
I'm trying to make a form with checkboxes which should subscribe a user to a forum in the database eventually.
I use this code to dynamically create a list of subscribed/unsubscribed forums for the current user:
//$checkboxes = array();
echo' <form action="" method="post">';
while($unsubscrlist = mysql_fetch_assoc($sublist))
{
//$checkboxes[] = $unsubscrlist['Name'];
echo '<input type="checkbox" checked="checked" name="subscrform[]"
value="' .$unsubscrlist['Name']. ' "/>' .$unsubscrlist['Name']. ' <br />';
}
while($subscrlist = mysql_fetch_assoc($notsublist))
{
// $checkboxes[] = $subscrlist['Name'];
echo '<input type="checkbox" name"subscrform[]"
value="' .$subscrlist['Name']. '"/>' .$subscrlist['Name']. '<br />';
}
echo '<br />
<input type="submit" value="Submit" />
</form>';
Then, to determine which checkboxes are checked I use this code:
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['subscrform']))
{
//echo 'getshereeee';
foreach($_POST['subscrform'] as $value)
{
//echo 'getshereeee';
echo $value;
}
}
Now the first checkboxes - to which the user is already subscribed -are output as value by this code, while the second list of checked checkboxes is never output as value somehow..
I thought this might had to do with using the same name twice. So I changed the first list to unsubscrform and did the check loop loop for both but still only get the first list as output values.
I feel like I'm missing something simple but can't really find out what. I would very much appreciate your help!
I just found a solution to my problem!
by changing
echo' <form action="" method="post">';
to
echo' <form name="subscrform" action="" method="post">';