paypal get multiple item_number - php

I have created a paypal cart form which add multiple product for payment:
<?php
$i=1;
foreach($p_result as $prod):
?>
<div class="image">
<img src="images/<?php $result = $SimpleUsers->prod($prod['pid']); foreach($result as $row):echo $row['product_img'];?>" alt="" width="97px" height="110px"/>
</div>
<div class="name">
<?php echo $row['product'].' -- ';echo $prod['month']." mesi";?>
</div>
<div class="price">
<?php echo "N. licenze:".$prod['quantity'];?>
</div>
<div class="price">
Price: <?php echo $row['price']*$prod['month']*$prod['quantity'];?>0€
</div>
<div class="btn">
<form action='<?php echo $paypal_url; ?>' method='post' name='cart'>
<input type='hidden' name='business' value='<?php echo $paypal_id;?>'>
<input type='hidden' name='cmd' value='_cart'>
<input type="hidden" name="upload" value="1">
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $prod['quantity']; ?>">
<input type='hidden' name='item_name_<?php echo $i; ?>' value='<?php echo $row['product'];?>'>
<input type='hidden' name='item_number_<?php echo $i; ?>' value='<?php echo $prod['pid'];?>'>
<input type='hidden' name='amount_<?php echo $i; ?>' value='<?php echo $row['price']*$prod['month'];endforeach; ?>'>
<?php $i++; ?>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='EUR'>
<input type='hidden' name='handling' value='0'>
<input type='hidden' name='cancel_return' value='http://www.example.com/paypal/cancel.php'>
<input type='hidden' name='return' value='http://www.example.com/paypal/success.php'>
<?php
endforeach;
?>
But on success.php page, I get all the variables, except item_number which is void
Success.php(part where I get variables)
$uid = $_SESSION['uid'];
$username=$_SESSION['username'];
$item_no = $_GET['item_number'];
$item_transaction = $_GET['tx'];
$item_price = $_GET['amt'];
$item_currency = $_GET['cc'];
How I can get item_number variable?

You have to use the array in input name to get the multiple values
<input type='hidden' name='item_number[]' value='<?php echo $prod['pid'];?>'>
You can get the values using
print_r($_GET['item_number']) //You will get a array of item number

Well when you're naming it in the form you're usinh
'item_number_<?php echo $i; ?>' (which can look like "item_number_3")
but when you try to call it your using $_GET['item_number']
you would have to call $_GET['item_number_2'] with the way you're naming it.
Hope that shed some light on it, for you.
edit ++++++++++++++++++++++++++++
If I were you I would change
<input type='hidden' name='item_number_<?php echo $i; ?>' value='<?php echo $prod['pid'];?>'>
to
<input type='hidden' name='item_number' value='<?php echo $prod['pid'];?>'>
and you call to $_GET['item_number'] should work fine.

Related

hidden values are not passing in form action

When I save this form all type="text" fields are working fine. But hidden field values are not passing.
If I changed from "hidden" to "text" it works fine. I don't know why I am getting this problem.
<form action="../model/meter-reading-model" method="POST">
<input type='hidden' name='hdnTakenDate' id='hdnTakenDate' value='<?php echo $TakenDate; ?>' />
<input type='hidden' name='hdnSiteHeadDbKey' id='hdnSiteHeadDbKey' value='<?php echo $SiteHeadDbKey; ?>' />
<button type='submit' name="btnSaveData" id="btnSaveData" class='btn btn-lg btn-danger'> Save Reading Data </button>
</form>
Receiving in another page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($SaveData)){
$TakenDate = mysqli_real_escape_string($conn, $_POST['hdnTakenDate']);
$SiteHeadDbKey = mysqli_real_escape_string($conn, $_POST['hdnSiteHeadDbKey']);
}
}
It solved for me when i change this
<input type='hidden' name='hdnTakenDate' id='hdnTakenDate' value='<?php echo $TakenDate; ?>' />
<input type='hidden' name='hdnSiteHeadDbKey' id='hdnSiteHeadDbKey' value='<?php echo $SiteHeadDbKey; ?>' />
to this
<input type='hidden' name='hdnTakenDate' id='hdnTakenDate' value='<?php echo $TakenDate; ?>' **/>**
<input type='hidden' name='hdnSiteHeadDbKey' id='hdnSiteHeadDbKey' value='<?php echo $SiteHeadDbKey; ?>' **/>**

how to get multiple products from cart to paypal payment

I want to get multiple products on paypal payment page. I am only getting a single first product at the moment. can someone help me out where I am wrong. below is my code..i searched google and found two more things to be changed. i.e. _xclick to _cart and one more <input type='hidden' value='1' name='upload'/>
Now I am getting your cart is empty.
$query = mysql_query("SELECT * FROM temporderdetails WHERE omid = '$ordermaster_id' " ) or die(mysql_error());
while($row = mysql_fetch_array($query)){
$productid = $row['productid'];
$quantity = $row['qty'];
$price = $row['price'];
$subtotal = $row['subtotal'];
$query1 = mysql_query("select product_name from products where product_id = '$productid'" ) or die(mysql_error());
while($row1 = mysql_fetch_array($query1)){
$product = $row1['product_name'];
<form action='<?php echo $payment_url ;?>' method='post'>
<input type="hidden" name="cmd" value="_cart">
<input type='hidden' name='business' value='<?php echo $payment_email;?>'>
<input type='hidden' name='item_name' value='<?php echo $product;?>'>
<input type='hidden' name='upload' value='1'>
<input type='hidden' name='quantity' value='<?php echo $quantity; ?>'>
<input type='hidden' name='amount' value='<?php echo $grandtotal;?>'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='return' value='<?php echo $payment_success;?>'>
<input type='hidden' name='cancel_return' value='<?php echo $payment_failed;?>'>
}
}
In case of multiple products you have to use the following variables for each product:
amount_x
item_name_x
where x is the product number (starting from 1). So, what you have to do is something like this:
<form action='<?php echo $payment_url ;?>' method='post'>
<input type="hidden" name="cmd" value="_cart">
<input type='hidden' name='business' value='<?php echo $payment_email;?>'>
<input type='hidden' name='upload' value='1'>
<input type='hidden' name='currency_code' value='USD'>
<input type='hidden' name='return' value='<?php echo $payment_success;?>'>
<input type='hidden' name='cancel_return' value='<?php echo $payment_failed;?>'>
In here you can get all your products (your "while" statement), use a counter variable, and then:
<input type='hidden' name='amount_<?php echo $counter;?>' value='<?php $price ?>'>
<input type='hidden' name='item_name_<?php echo $counter;?>' value='<?php echo $product?>'>
<?php $counter++ ?>
Finally close the form
</form>

PHP email send form - drop down list on $_POST send form

Here is my html and php code:
<!-- Form Code Start -->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset >
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
Years Active (from and to):<br/>
<select name='years_active_from'>
<option value='<?php echo $formproc->SafeDisplay('NULL') ?>'>select</option>
<option value='<?php echo $formproc->SafeDisplay('from 2013') ?>'>2013</option>
<option value='<?php echo $formproc->SafeDisplay('from 2012') ?>'>2012</option>
</select>
<br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
I am trying to get the different drop down options to change the var $years_active_from; to each of the different years, 2012, 2013 and post NULL if the drop down menu is not used.
value='<?php echo $formproc->SafeDisplay('NULL') ?>' is not changing the $years_active_from, what is the correct coding for this?
Honestly, I am not 100% sure I understand what you are looking for, but my guess is that you want to have the first drop down option pre-selected on page load. For that, you would need to do add the selected attribute to the option you want to show as selected:
<option selected value='<?php echo $formproc->SafeDisplay('NULL') ?>'>select</option>

Mysql Query clearing a row instead of updating

I have no idea why this is acting this way, I did echo out $sqll in my code and it shows all the right information but when it goes back to the page with the information it is blank.
Here is the script
<?php
include("header.php");
include("sidebar.php");
$memberon = $_GET['user'];
$getmember = mysql_query("SELECT * FROM accounts WHERE username='".$memberon."'");
$member = mysql_fetch_array($getmember);
?>
<h2>Edit User</h2>
<?php
$points = asql($_POST['points']);
$cash = asql($_POST['cash']);
$banned = asql($_POST['banned']);
$completed = asql($_POST['completed']);
$confirm= asql($_POST['confirm']);
$referral= asql($_POST['ref']);
$email= asql($_POST['email']);
$username= asql($_POST['username']);
$fname= asql($_POST['fname']);
$lname= asql($_POST['lname']);
$add= asql($_POST['address']);
$state= asql($_POST['state']);
$country= asql($_POST['country']);
$postal= asql($_POST['postal']);
$apt= asql($_POST['suite']);
$city= asql($_POST['city']);
$phone= asql($_POST['phone']);
$dob= asql($_POST['dob']);
if ($_POST['subm']) {
if($points <> $member['points'] || $cash <> $member['current_b']){
$final_report = "Checking";
print"This users balance has been updated, please input your pass code to confirm these changes <br />
<form method='post' action=''><input type='hidden' name='points' value='$points'><input type='hidden' name='cash' value='$cash'><input type='hidden' name='banned' value='$banned'><input type='hidden' name='confirm' value='$confirm'><input type='hidden' name='ref' value='$referral'><input type='hidden' name='email' value='$email'><input type='hidden' name='fname' value='$fname'><input type='hidden' name='lname' value='$lname'><input type='hidden' name='address' value='$add'><input type='hidden' name='state' value='$state'><input type='hidden' name='country' value='$country'><input type='hidden' name='postal' value='$postal'><input type='hidden' name='suite' value='$apt'><input type='hidden' name='city' value='$city'><input type='hidden' name='phone' value='$phone'><input type='hidden' name='dob' value='$dob'><input type='password' name='passcode' /><input type='submit' name='pcheck' value='Sumbit' /></form>";
}
else
{
$final_report = "";
}
if($final_report == NULL){
$updatemembers = mysql_query("UPDATE accounts SET points='$points', current_b='$cash', level='$banned', email_check='$confirm', referral='$referral', username='$username', fname='$fname', lname='$lname', email='$email', address='$add', state='$state', country='$country', postal='$postal', suite='$apt', city='$city', phone='$phone', dob='$dob' WHERE username='".$memberon."'") or die(mysql_error());
print "You Have Successfully Updated this Information";
header("Refresh: 2;url=edit.php?user=".$memberon."");
}
}
if($_POST['pcheck']){
$pchecki = asql($_POST['passcode']);
$pchecks = md5($pchecki);
$check = mysql_query("SELECT * FROM panel_access WHERE psn = '".$_SESSION['aname']."'") or die(mysql_error());
$checkar = mysql_fetch_array($check);
$final_report = "Checking.";
if($pchecks != $checkar['change_ab']){
$final_report = "That password is incorrect.";
print "".$final_report."";
header("Refresh: 2;url=edit.php?user=".$memberon."");
}
else
{
$final_report = "";
}
if($final_report == NULL){
$sqll = "UPDATE accounts SET points='".$points."', current_b='".$cash."', level='".$banned."', email_check='".$confirm."', referral='".$referral."', username='".$username."', fname='".$fname."', lname='".$lname."', email='".$email."', address='".$add."', state='".$state."', country='".$country."', postal='".$postal."', suite='".$apt."', city='".$city."', phone='".$phone."', dob='".$dob."' WHERE username='".$memberon."'";
$updatemember = mysql_query($sqll) or die(mysql_error());
print "You Have Successfully Updated this Information ".$sqll."";
header("Refresh: 2;url=edit.php?user=".$memberon."");
}
}
if(!isset($_POST['subm']) && !isset($_POST['pcheck']))
{
?>
<div class='form'>
<form action='' method='post'><input type=hidden name=subm value=1>
<div class="element">
<label for='email'>Email:</label>
<input type='text' name='email' id='email' value='<?php echo $member['email'] ?>' size='54' />
</div>
<div class="element">
<label for='username'>Username:</label>
<input type='text' name='username' id='username' value='<?php echo $member['username'] ?>' size='54' />
</div>
<div class="element">
<label for='ip'>IP Address:</label>
<input type='text' name='ip' id='ip' value='<?php echo $member['ip'] ?>' size='54' readonly='readonly' />
</div>
<div class="element">
<label for='banned'>Banned: <font color='red' size='1'><b>1=No 2=Yes</b></font></label>
<input type='text' name='banned' id='banned' value='<?php echo $member['level'] ?>' size='54' />
</div>
<div class="element">
<label for='confirm'>E-Mail Confirmed: <font color='red' size='1'>0=No 1=Yes</font></label>
<input type='text' name='confirm' id='confirm' value='<?php echo $member['email_check'] ?>' size='54' />
</div>
<div class="element">
<label for='ref'>Referral:</label>
<input type='text' name='ref' id='ref' value='<?php echo $member['referral'] ?>' size='54' />
</div>
<div class="element">
<label for='points'>Points:</label>
<input type='text' name='points' id='points' value='<?php echo $member['points'] ?>' size='54' />
</div>
<div class="element">
<label for='cash'>Cash:</label>
<input type='text' name='cash' id='cash' value='<?php echo $member['current_b'] ?>' size='54' />
</div>
<div class="element">
<label for='fname'>First Name:</label>
<input type='text' name='fname' id='fname' value='<?php echo $member['fname'] ?>' size='54' />
</div>
<div class="element">
<label for='lname'>Last Name:</label>
<input type='text' name='lname' id='lname' value='<?php echo $member['lname'] ?>' size='54' />
</div>
<div class="element">
<label for='phone'>Phone:</label>
<input type='tel' name='phone' id='phone' value='<?php echo $member['phone'] ?>' size='54' />
</div>
<div class="element">
<label for='dob'>Date of Birth:</label>
<input type='text' name='dob' id='dob' value='<?php echo $member['dob'] ?>' size='54' />
</div>
<div class="element">
<label for='address'>Address:</label>
<input type='text' name='address' id='address' value='<?php echo $member['address'] ?>' size='54' />
</div>
<div class="element">
<label for='suite'>Suite/Apt.:</label>
<input type='text' name='suite' id='suite' value='<?php echo $member['suite'] ?>' size='54' />
</div>
<div class="element">
<label for='country'>Country:</label>
<input type='text' name='country' id='country' value='<?php echo $member['country'] ?>' size='54' />
</div>
<div class="element">
<label for='state'>State:</label>
<input type='text' name='state' id='state' value='<?php echo $member['state'] ?>' size='54' />
</div>
<div class="element">
<label for='city'>City:</label>
<input type='text' name='city' id='city' value='<?php echo $member['city'] ?>' size='54' />
</div>
<div class="element">
<label for='postal'>Postal Code:</label>
<input type='text' name='postal' id='postal' value='<?php echo $member['postal'] ?>' size='54' />
</div>
<?php
print"<dl class='submit'>
<input type='submit' name='submit' id='submit' value='Submit' />
</dl>
</form>
</div> ";
}
include("footer.php");
?>
On a side note I know that mysql_query and the likes are in the process of being deprecated, I want to note that I did not write this, just doing some editing for a client, and this part is happening to be a pain in the rear.
Also its only the query in if($_POST['pcheck']) that isn't working, the first query for if($_POST['subm'] works fine
First, you have an empty string at the end. This doesn't hurt, but it has no purpose either.
You redirect the page to edit.php?user=$memberon, but $memberon isn't set when you get a POST request. You can have either GET or POST, but not both.
I would guess, you must redirect to
edit.php?user=$username

Set multiple fields of form on particular radio button click

I'm developing a web app in which I've to integrate a Paypal account. There are many radio buttons on the page that represents various credits and it's price and like wise. My Problem is, I want some functionality through which I can set various other fields of form on one of the radio button click. And those values are different for every radio button.
<form action='<?php echo $paypal_url; ?>' method='post' name='form'>
<div class="crea_paka_title">Creadit Pakages</div>
<?php
foreach($admin_credits as $credits){
?>
<div class="creadit_fields">
<span class="for_radio">
<input type="radio" name="1" id="<?php echo $credits['AdminCredit']['id'];?>" value="" />
</span>
<span class="for_creadit">
<?php echo $credits['AdminCredit']['tx_total_credits']; ?> Credits
</span>
<span class="for_cre_value">
$<?php echo $credits['AdminCredit']['nu_total_price']; ?>
</span>
</div>
<div style="clear:both;"></div>
<?php
}
?>
<input type='hidden' name='business' value='<?php echo $paypal_id; ?>'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='item_name' value='<?php echo $credits['AdminCredit']['tx_total_credits'];?> Credits'>
<input type='hidden' name='item_number' value='<?php echo $credits['AdminCredit']['id'];?>'>
<input type='hidden' name='amount' value='<?php echo $credits['AdminCredit']['nu_total_price'];?>'>
<input type='hidden' name='no_shipping' value='1'>
<input type='hidden' name='currency_code' value='USD'>
Like as above in my code I've to change the values of inputs on radio button click. Any suggestions are appreciated.
jQuery will do it:
$("#rbID").click(finction(){
$("otherRB").attr("checked",true);
});

Categories