Jump to content

Form does not seem to be posting values to script


Paul_Withers
Go to solution Solved by mac_gyver,

Recommended Posts

Hi, I got this form which passes hidden values as well as a select menu.  The only thing is, it doesnt seem to post the form data to the script.

 

Here is the form

echo '<form action="regsale.php" method="POST">';
echo '<input type="hidden" name="username" value="<?php echo $username ?>"';
echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>"';
echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>"';
echo '<input type="hidden" name="cost" value="<?php echo $cost ?>"';
echo '<input type="hidden" name="business" value="<?php echo $business ?>"';
echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>"';
echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>"';

echo "<ul class='results'>";
echo '<li>Quantity:</li>';      
echo '<select name="quantity">';
echo "<option value='$quantity'>Maximum of $quantity available</option>";
for ($q=1; $q<=$quantity; $q++) 
{
    echo "<option value='$q'>$q</option>";
}
echo '</select>';
echo' </ul><br>';



echo '<div align="center">';
echo '<br>';
echo '<input type="submit" value="Confirm Purchase"><br>';
echo '</form><br>';

And here is the script that the form is posted to

<?php
include 'init.php';
include 'includes/overall/header.php';
include 'includes/logo.php';


if (!isset($_SESSION['loggedin'])) {
   die("You must be logged in to submit care guides"); //this causes to script to stop executing and lets the user know there is a problem

/*
Note:  instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave.
*/
}

//else {  //logged in 
elseif (isset($_SESSION['loggedin']) ){  //logged in 
$username = $_SESSION['loggedinuser'];


if	(isset($_POST['listing_title'], $_POST['speciesCommon'], $_POST['cost'], $_POST['business'], $_POST['postage_cost'], $_POST['multipostage'], $_POST['quantity'] ) ) {

    if( $_POST['listing_title'] == "" )
    {
        echo "Error: Please go back and try again";
    }
     elseif( $_POST['speciesCommon'] == "" )
    {
        echo "Error: Please go back and try again";
    }
  elseif( $_POST['cost'] == "" )
    {
        echo "Error: Please go back and try again";
    }
    elseif( $_POST['business'] == "" )
    {
        echo "Error: Please go back and try again";
    }
    elseif( $_POST['postage_cost'] == "" )
    {
        echo "Error: Please go back and try again";
    }
    elseif( $_POST['multipostage'] == "" )
    {
        echo "Error: Please go back and try again";
    }
    elseif( $_POST['quantity'] == "" )
    {
        echo "Error: Please go back and try again";
    
   
} else {

  
  	
    		
	$listing_title = mysqli_real_escape_string($con, $_POST['listing_title']);
        $speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']);
        $cost = mysqli_real_escape_string($con, $_POST['cost']);        
        $business = mysqli_real_escape_string($con, $_POST['business']);
        $postage_cost = mysqli_real_escape_string($con, $_POST['postage_cost']);
        $multipostage = mysqli_real_escape_string($con, $_POST['multipostage'] );		
        $quantity = mysqli_real_escape_string($con, $_POST['quantity'] );		



if( $multipostage == "per item" )
    {
    $postage_cost = $quantity * $postage_cost;
    }
    elseif( $multipostage == "Combined Postage" )
    {
	$postage_cost;
    }     

$total = $cost + $postage_costage;

// Writes customer_sales information to the MySQL database                    

        	$sqlCustomerSales = "INSERT INTO customer_sales(username, listing_title, speciesCommon, total, business, postage_cost, multipostage ) VALUES (
                        '". $username ."',
                        '". $listing_title ."',                                                                                        
                        '". $speciesCommon ."',
                        '". $total ."',
                        '". $business ."',
                        '". $postage_cost ."',
                        '". $multipostage."'                       
                        )";
          
$result1 = mysqli_query($con, $sqlCustomerSales); 

// This writes the transaction to the MySQL database

$memo = $listing_title;
$datetime = date("Y-m-d H:i:s");

$regCustomerTransaction = "INSERT INTO customer_transactions(username, datetime, cost, postage_cost, memo) VALUES (
					'". $username ."', 
					'". $datetime ."', 
					'". $cost ."', 
					'". $postage_cost ."',
					'". $memo."'
					)";
		 
// Query the database 
$result2 = mysqli_query($con, $regCustomerTransaction); 
}

// This writes the user_stats to the MySQL database

$total_items_sold = $quantity;

$regUserStats = "INSERT INTO user_stats(username, datetime, total, items_listed, bonus_credits, last_credit_purchase, total_care_guides, total_items_sold,
total_currently_listed_items, total_items_purchased, total_diary_entries, feedback ) VALUES (
					'". $username ."', 
					'". $datetime ."',
					'". $total ."',  					
					'". $quantity ."',  					
					'". $subtotal ."',  					
					'". $last_credit_purchase ."',  					
					'". $total_care_guides ."',  					
					'". $total_items_sold ."',  					
					'". $total_currently_listed_items ."',  					
					'". $total_items_purchased ."',  					
					'". $total_diary_entries ."',  					
					'". $feedback."'
										)";
		 
// Query the database 

$result3 = mysqli_query($con, $regUserStats); 
}

?>


<h1>Payment to <?php echo $username ?></h1><br>

<?php
echo '<strong>Thank you for confirming you would like to purchase $speciesCommon; </strong>';
echo '<br>';
echo '<strong>Your payment comes to a total of $total; </strong></h2>';
echo '<br>';
echo '<br>';
echo 'Please complete payment using the PayPal button<br>';
echo '<br>';
echo '<br>';
?>

<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="shipping" value="<?php echo $postage_cost ?>">
<input type="hidden" name="business" value="<?php echo $business ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php echo $speciesCommon ?>">
<input type="hidden" name="amount" value="<?php echo $cost ?>">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="OnButton1(); OnButton2();" alt="PayPal – The safer, easier way to pay online." >
<img alt="" align="center" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></form>


<?php
} else { 
 
	echo 'Sorry we were unable to process your listing. Please contact <a href="mailto:helpdesk@aquapetcentre.com?Subject=Listing%20error">helpdesk@aquapetcentre.com';
   die(); 
 
include('includes/overall/footer.php');
}


// Close the connection 
mysqli_close($con); 
?>

<h1>Payment to <?php echo $username ?></h1><br> works, but I think that is because it is passed in the SESSION.

 

Any other $variable such as those below

echo '<strong>Thank you for confirming you would like to purchase $speciesCommon; </strong>';
echo '<br>';
echo '<strong>Your payment comes to a total of $total; </strong></h2>';

does not work.

 

Why is the form not posting the values to the database.

 

Just in case it helps, the form gets its values from the database, and the values are displayed in the sales page on which the form is contained. Here is the page containing the form.

<?php
include 'init.php';
include 'includes/overall/header.php';
include 'includes/logo.php';



if (!isset($_SESSION['loggedin'])) {
   die("You must be logged in to view this page!"); //this causes to script to stop executing and lets the user know there is a problem

/*
Note:  instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave.
*/
}

//else {  //logged in 
elseif (isset($_SESSION['loggedin']) ){  //logged in 

$username = $_SESSION['loggedinuser'];

$results = $con->query("SELECT * FROM user WHERE username = '$username';");
while($row = $results->fetch_array()) {
$business = $row['paypal_email'];


$user_id = $_GET['user_id'];

$results1 = $con->query("SELECT * FROM live_sales WHERE user_id = '$user_id';");
while($row = $results1->fetch_array()) {

$username  			= $row['username'];
$fishtype    		= $row['fishtype'];
$speciesCommon 		= $row['speciesCommon'];
$speciesScientific  = $row['speciesScientific'];
$listing_title    	= $row['listing_title'];
$age 		        = $row['age'];
$quantity	        = $row['quantity'];
$origin       	    = $row['origin'];
$size               = $row['size'];
$environment 		= $row['environment'];
$waterChemistry	    = $row['waterChemistry'];
$temperature       	= $row['temperature'];
$feeding            = $row['feeding'];
$sexing 		    = $row['sexing'];
$compatability	    = $row['compatability'];
$temperament      	= $row['temperament'];
$breeding           = $row['breeding'];
$comments 		    = $row['comments'];
$postage_type	    = $row['postage_type'];
$postage_cost      	= $row['postage_cost'];
$multipostage		= $row['multipostage'];
$cost      			= $row['cost'];


echo "<div class='result'>";
echo "<h3>$speciesCommon</h3>";
echo "<h2>$listing_title</h2>";
echo "<ul class='results'>";
echo "<li>Species</li>" . str_replace("_"," "," $fishtype") . "<br>";
echo "<li>Common Name:</li> $speciesCommon<br>";
echo "<li>Scientific Name:</li> $speciesScientific<br>";
echo "<li>Age:</li> $age<br>";
echo "<li>Quantity:</li> $quantity<br>";
echo "<li>Price per item:</li> £$cost<br>";
echo "<li>Origin:</li> $origin<br>";
echo "<li>Size:</li>$size<br>";
echo "<li>Environment:</li> $environment<br>";
echo "<li>Water Chemistry</li> $waterChemistry<br>";
echo "<li>Temperature:</li> $temperature<br>";
echo "<li>Feeding:</li> $feeding<br>";
echo "<li>Sexing:</li> $sexing<br>";
echo "<li>Compatability:</li> $compatability<br>";
echo "<li>Temperament:</li> $temperament<br>";
echo "<li>Breeding:</li>$breeding<br>";
echo "<li>Comments:</li> $comments<br>";
echo "<li>Postage Type:</li>$postage_type<br>";
echo "<li>Postage Cost:</li> £$postage_cost $multipostage<br>";



echo '<form action="regsale.php" method="POST">';
echo '<input type="hidden" name="username" value="<?php echo $username ?>"';
echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>"';
echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>"';
echo '<input type="hidden" name="cost" value="<?php echo $cost ?>"';
echo '<input type="hidden" name="business" value="<?php echo $business ?>"';
echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>"';
echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>"';

echo "<ul class='results'>";
echo '<li>Quantity:</li>';      
echo '<select name="quantity">';
echo "<option value='$quantity'>Maximum of $quantity available</option>";
for ($q=1; $q<=$quantity; $q++) 
{
    echo "<option value='$q'>$q</option>";
}
echo '</select>';
echo' </ul><br>';



echo '<div align="center">';
echo '<br>';
echo '<input type="submit" value="Confirm Purchase"><br>';
echo '</form><br>';

 
echo '<br><br>
</div>';


exit();
}
} 
echo 'Sorry but we could not find any results.';
}
include 'includes/overall/footer.php';
?>

Any help is always appreciated. 

 

aquaman

Link to comment
Share on other sites

Yes I know, I forgot to add the extra > in

 

so the form should read

echo '<form action="regsale.php" method="POST">';
echo '<input type="hidden" name="username" value="<?php echo $username ?>">';
echo '<input type="hidden" name="listing_title" value="<?php echo $listing_title ?>">';
echo '<input type="hidden" name="speciesCommon" value="<?php echo $speciesCommon ?>">';
echo '<input type="hidden" name="cost" value="<?php echo $cost ?>">';
echo '<input type="hidden" name="business" value="<?php echo $business ?>"';
echo '<input type="hidden" name="postage_cost" value="<?php echo $postage_cost ?>">';
echo '<input type="hidden" name="multipostage" value="<?php echo $multipostage ?>">';

echo "<ul class='results'>";
echo '<li>Quantity:</li>';      
echo '<select name="quantity">';
echo "<option value='$quantity'>Maximum of $quantity available</option>";
for ($q=1; $q<=$quantity; $q++) 
{
    echo "<option value='$q'>$q</option>";
}
echo '</select>';

but it still doesnt work :(

Link to comment
Share on other sites

Changing it to

echo '<form action="regsale.php" method="POST">';
echo '<input type="hidden" name="username" value="$username">';
echo '<input type="hidden" name="listing_title" value="$listing_title">';
echo '<input type="hidden" name="speciesCommon" value="$speciesCommon">';
echo '<input type="hidden" name="cost" value="$cost">';
echo '<input type="hidden" name="business" value="$business"';
echo '<input type="hidden" name="postage_cost" value="$postage_cost">';
echo '<input type="hidden" name="multipostage" value="$multipostage">';

echo '<li>Quantity:</li>';      
echo '<select name="quantity">';
echo "<option value='$quantity'>Maximum of $quantity available</option>";
for ($q=1; $q<=$quantity; $q++) 
{
    echo "<option value='$q'>$q</option>";
}
echo '</select>';
echo' <br>';
echo '</div>';


echo '<div align="center">';
echo '<br>';
echo '<input type="submit" value="Confirm Purchase"><br>';
echo '</form><br>';

doesnt work either :(

Link to comment
Share on other sites

  • Solution

php variables are NOT replaced with their value inside of an over-all single-quoted string. you would either need to use initial and final double-quotes or use concatenation.

 

p.s. i seriously doubt your form processing code is running, because your big long isset() statement is testing for at least one form field that doesn't exist. it was mentioned in a previous thread of your's that you only need to test for one of the known form fields to qualify running the form processing code.

Link to comment
Share on other sites


<?php
include 'init.php';
include 'includes/overall/header.php';
include 'includes/logo.php';


if (!isset($_SESSION['loggedin'])) {
die("You must be logged in to submit care guides"); //this causes to script to stop executing and lets the user know there is a problem

/*
Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave.
*/
}

//else { //logged in
elseif (isset($_SESSION['loggedin']) ){ //logged in
$username = $_SESSION['loggedinuser'];


if (isset($_POST['listing_title'] ) ) {

if( $_POST['listing_title'] == "" )
{
echo "Error: Please go back and try again";
}
elseif( $_POST['speciesCommon'] == "" )
{
echo "Error: Please go back and try again";
}
elseif( $_POST['cost'] == "" )
{
echo "Error: Please go back and try again";
}
elseif( $_POST['business'] == "" )
{
echo "Error: Please go back and try again";
}
elseif( $_POST['postage_cost'] == "" )
{
echo "Error: Please go back and try again";
}
elseif( $_POST['multipostage'] == "" )
{
echo "Error: Please go back and try again";
}
elseif( $_POST['quantity'] == "" )
{
echo "Error: Please go back and try again";


} else {




$listing_title = mysqli_real_escape_string($con, $_POST['listing_title']);
$speciesCommon = mysqli_real_escape_string($con, $_POST['speciesCommon']);
$cost = mysqli_real_escape_string($con, $_POST['cost']);
$business = mysqli_real_escape_string($con, $_POST['business']);
$postage_cost = mysqli_real_escape_string($con, $_POST['postage_cost']);
$multipostage = mysqli_real_escape_string($con, $_POST['multipostage'] );
$quantity = mysqli_real_escape_string($con, $_POST['quantity'] );



if( $multipostage == "per item" )
{
$postage_cost = $quantity * $postage_cost;
}
elseif( $multipostage == "Combined Postage" )
{
$postage_cost;
}

$total = $cost + $postage_costage;

// Writes customer_sales information to the MySQL database

$sqlCustomerSales = "INSERT INTO customer_sales(username, listing_title, speciesCommon, total, business, postage_cost, multipostage ) VALUES (
'". $username ."',
'". $listing_title ."',
'". $speciesCommon ."',
'". $total ."',
'". $business ."',
'". $postage_cost ."',
'". $multipostage."'
)";

$result1 = mysqli_query($con, $sqlCustomerSales);

// This writes the transaction to the MySQL database

$memo = $listing_title;
$datetime = date("Y-m-d H:i:s");

$regCustomerTransaction = "INSERT INTO customer_transactions(username, datetime, cost, postage_cost, memo) VALUES (
'". $username ."',
'". $datetime ."',
'". $cost ."',
'". $postage_cost ."',
'". $memo."'
)";

// Query the database
$result2 = mysqli_query($con, $regCustomerTransaction);
}

// This writes the user_stats to the MySQL database

$total_items_sold = $quantity;

$regUserStats = "INSERT INTO user_stats(username, datetime, total, items_listed, bonus_credits, last_credit_purchase, total_care_guides, total_items_sold,
total_currently_listed_items, total_items_purchased, total_diary_entries, feedback ) VALUES (
'". $username ."',
'". $datetime ."',
'". $total ."',
'". $quantity ."',
'". $subtotal ."',
'". $last_credit_purchase ."',
'". $total_care_guides ."',
'". $total_items_sold ."',
'". $total_currently_listed_items ."',
'". $total_items_purchased ."',
'". $total_diary_entries ."',
'". $feedback."'
)";

// Query the database

$result3 = mysqli_query($con, $regUserStats);
}

?>


<h1>Payment to <?php echo $username ?></h1><br>


<strong>Thank you for confirming you would like to purchase <?php echo $speciesCommon ?> </strong>
<br>
<strong>Your payment comes to a total of <?php echo $total ?> </strong></h2>
<br>
<br>
Please complete payment using the PayPal button
<br>
<br>
<strong>NOTE: If you do not complete this purchase, the seller may report you and a strike will be marked on your account.
<br>
<br>
Three strikes will mean your account will be suspended and you will not be able to register again.</strong><br>
<br>


<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="shipping" value="<?php echo $postage_cost ?>">
<input type="hidden" name="business" value="<?php echo $business ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php echo $speciesCommon ?>">
<input type="hidden" name="amount" value="<?php echo $cost ?>">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="OnButton1(); OnButton2();" alt="PayPal – The safer, easier way to pay online." >
<img alt="" align="center" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></form>


<?php
} else {

echo 'Sorry we were unable to process your listing. Please contact <a href="mailto:helpdesk@aquapetcentre.com?Subject=Listing%20error">helpdesk@aquapetcentre.com';
die();

include('includes/overall/footer.php');
}


// Close the connection
mysqli_close($con);
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.