phpcode error updating values into url please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harshith
Forum Newbie
Posts: 3
Joined: Thu May 03, 2018 12:25 am

phpcode error updating values into url please help

Post 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>
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: phpcode error updating values into url please help

Post 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'] : '';
?>
(#10850)
harshith
Forum Newbie
Posts: 3
Joined: Thu May 03, 2018 12:25 am

Re: phpcode error updating values into url please help

Post 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>
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: phpcode error updating values into url please help

Post 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)
(#10850)
harshith
Forum Newbie
Posts: 3
Joined: Thu May 03, 2018 12:25 am

Re: phpcode error updating values into url please help

Post 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>
User avatar
Christopher
Site Administrator
Posts: 13592
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: phpcode error updating values into url please help

Post 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'
(#10850)
Post Reply