Page 1 of 1

phpcode error updating values into url please help

Posted: Thu May 03, 2018 12:37 am
by harshith
Below code i am using to create a text box and update those values into the url but i am unable to do it.I am getting errors please help me with it.
error-undefined variables and also unable to fetch the values into url.
Thank you.

Code: Select all

<!DOCTYPE html>
<html>
<body>
<form action="" method="post">
number:<input name="number" type="text" value="7989212020">
op:<input name="op" type="text" value="4">
amount:<input name"amount" type="number" value="100">
</form>
<?php
$number=$_REQUEST['number'];
$op=$_REQUEST['op'];
$amount=$_REQUEST['amount'];
?>
<div><a href="http://api.rechapi.com/recharge.php?format=text&token=&mobile=<?php echo $number;?>&amount=<?php echo $amount;?>&opid=<?php echo $op;?>&urid=12345"><input type="button" name="button" value="RECHARGE"></a></div>
</body>
</html>

Re: phpcode error updating values into url please help

Posted: Thu May 03, 2018 12:43 pm
by Christopher
You will get errors the first time you go to the page because the $_REQUEST array values are not set. Always check that values are set.

Also, this form is not secure. A user can pass HTML to the form to inject code into the page. Always filter and validate all input.

Code: Select all

<?php
$number= isset($_REQUEST['number']) ? $_REQUEST['number'] : '';
$op= isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
$amount= isset($_REQUEST['amount']) ? $_REQUEST['amount'] : '';
?>

Re: phpcode error updating values into url please help

Posted: Fri May 04, 2018 12:27 am
by harshith
sir ill secure the form later. After your instruction i am using the below code errors are solved but still i am unable to fetch the textfields values into the url.
<!DOCTYPE html>
<html>
<body>
<form action="" method="post">
number:<input name="number" type="text" value="">
op:<input name="op" type="text" value="">
amount:<input name"amount" type="number" value="">
</form>
<?php $number= isset($_REQUEST['number']) ? $_REQUEST['number'] : '';?>
<?php $op= isset($_REQUEST['op']) ? $_REQUEST['op'] : '';?>
<?php $amount= isset($_REQUEST['amount']) ? $_REQUEST['amount'] : '';?>
<div><a href="http://api.rechapi.com/recharge.php?for ... bile=<?php echo $number;?>&amount=<?php echo $amount;?>&opid=<?php echo $op;?>&urid=12345"><input type="button" name="button" value="RECHARGE"></a></div>
</body>
</html>

Re: phpcode error updating values into url please help

Posted: Fri May 04, 2018 5:46 pm
by Christopher
What happens when you submit the form? You don't have an action URL or a submit button in the form. You could also wrap the code that creates the link in an if() to only show that if the form is submitted (check HTTP METHOD)

Re: phpcode error updating values into url please help

Posted: Sat May 05, 2018 1:19 pm
by harshith
sir please check the below code .my requirement is when user enters their details the details should be updated in the url and by clicking the submit button the url should be loaded.where should i place this url in the code? and i made changes to the code by your previous instruction.


url=http://api.rechapi.com/recharge.php?for ... bile=<?php echo $_number;?>&amount=<?php echo $_amount;?>&opid=<?php echo $provider_id;?>&urid=12345"



<!DOCTYPE html>
<html>
<body>

<form method="post">
number:<input id="number" name="number" placeholder="10 Digits mobilenumber" type="number" >
op:<input id="op" name="op"placeholder="select an operator" type="number" >
amount:<input id="amount" name="amount"placeholder="select an operator" type="number">
<input type="button" name="submit" value="submit">
<?php
if (isset($_REQUEST['submit']))
{
$number= isset($_REQUEST['number']) ? $_REQUEST['number'] : '';
$op= isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
$amount= isset($_REQUEST['amount']) ? $_REQUEST['amount'] : '';
}
?>
</form>
</body>
</html>

Re: phpcode error updating values into url please help

Posted: Sat May 05, 2018 6:57 pm
by Christopher
The submit field may not be sent if the user uses the Enter key to submit the form. Instead, check $_SERVER['REQUEST_METHOD'] == 'POST'