Jump to content

The problem is superglobals (post) values are not defined


JoshEir

Recommended Posts

I am having trouble with passing values with a POST to another php file.  I am getting the error :  undefined index : productID and undefined index: filename.  I have also tried :  <form   method = \"POST?pdib=$processID&filename=$filename\" action = \"upload2.php\"  >  When I look at the array of superglobals, they are both defined.  Thank you! 

 Here is the code :

drawfirsttwoforms:

$sql = "SELECT ProductFilename, ProductName, ProductID, ProductDescription,ProductCost,ProductQuantity, ProductCatTitle FROM products 
INNER JOIN customers ON customers.CustomerID = products.CustomerID 
WHERE ((products.ProductKeyWord1 = ?) 
OR (products.ProductKeyWord2 = ?) OR (products.ProductKeyWord3 = ? ))  AND (products.ProductCatTitle = ?) ";

$stmt = $dbo->prepare($sql);
$stmt->bindParam(1, $keyword1);
$stmt->bindParam(2, $keyword1);
$stmt->bindParam(3, $keyword1);
$stmt->bindParam(4, $titleOfSelectedDropDown);

$stmt->execute();

while ($row = $stmt->fetch()) {

//these variables do have values here
$productID = $row['ProductID'];
$filename = $row['ProductFilename'];

$string1 .=  "  
<div  class = \"A\" id = \"$mainDiv\">
<p id = \"link1\">product id   :$productID</p>
<p>category id  :$category</p>
<div class = \"A\" id = \"endz\"></div>
<div class = \"A\" id = \"startz\"></div>
<div class=\"container\">
<div id = \"testing\" >testing <div>
<div id = \"$displayID\" >  </div>
<div class=\"row\" >
<div class=\"col\">
	
	<form   method = \"POST\" action = \"upload2.php\"  >
      
      
    
	<input type=hidden id='$productID' name= '$productID' value=\"A\">
	<input type=hidden id=\"$filename\" name=$filename value=\"B\">
	
      
      
      <button value = \"Submit\" type = \"submit\"  >submit it</button>
	</form>
	<iframe id=\"upload_target\" name=\"upload_target\"  style=\"width:0;height:0;border:0px solid #fff;\"></iframe> 
	<img width=\"120\" height =\"120\"  id = \"$imageID\"  src=\"../php proj/uploads/$filename?<?php echo filemtime($filename)?>\">
	<button    onclick = \"imageRefresh( '{$filename}', '{$imageID}', '{$_SESSION["msg"]}' )\" >Display</button>
	</div>


AFTER:
  

if (!isset($myObj) && isset($string1))
{
$myObj = new stdClass();
$myObj->htmlstuff = $string1;


//Encode the data as a JSON string
$jsonStr = json_encode($myObj);
echo $jsonStr;
}

 

function printHTML1(keyword){ 
	
	
	const element = document.getElementById("dropDown1");
		
	//const checkValue = element.options[element.selectedIndex].value;
	const checkText = element.options[element.selectedIndex].text;
	
	var val1 = checkText;

	var xmlhttp = new XMLHttpRequest();
	
	
	var keyword1 = keyword;
	var url = "drawfirsttwoforms.php?keyword=" + keyword.value + "&" + "val1=" + val1;
	


	xmlhttp.onreadystatechange = function() {
		
	if (this.readyState == 4 && this.status == 200) {
		
		
		var jsonData = JSON.parse(this.responseText);
		var answerHtml = jsonData.htmlstuff;
		document.getElementById("codehere").innerHTML = answerHtml;

		createAndModifyDivs();


		}
	};
	
	xmlhttp.open("GET", url , true);
	
	xmlhttp.send();
	
	
}

 

upload2.php


<?php
session_start();
$productID = $_POST['productID'];
$filename = $_POST['filename'];

 

Link to comment
Share on other sites

10 minutes ago, JoshEir said:

<input type=hidden id='$productID' name= '$productID' value=\"A\">

<input type=hidden id=\"$filename\" name=$filename value=\"B\">

If $productID contains '123' and $filename contains 'abc.txt' then upload2 will receive

  • $_POST['123'] with a value of 'A'
  • $_POST['abc.txt'] with a value of 'B'

It looks like you need

<input type='hidden' name='productID' value='$productID'>
<input type='hidden' name='filename' value='$flename'>

 

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.