JoshEir Posted March 18, 2021 Share Posted March 18, 2021 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']; Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/ Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 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'> Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585189 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 Still doesn't work, its odd. Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585190 Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 put this at the top of upload2.php so you can see what's being posted to it echo '<pre>' . print_r($_POST, 1) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585191 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 The response is Array() Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585192 Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 Then the form data isn't being submitted (to upload2) Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585193 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 Well, as you can see the action is that, however there is an iframe. Any clue? Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585194 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 Oh, Array ( [1439] => 1439 [A5_png] => A5.png ) Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585195 Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 Not from what you've posted. I get no sense of structure or sequence so I don't know how it all hangs together. Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585196 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 I just updated. Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585197 Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 1 minute ago, JoshEir said: Oh, Array ( [1439] => 1439 [A5_png] => A5.png ) Looks like you still have name='$productID' instead of name = 'productID' Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585198 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 That seemed to do it, what was the problem? Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585199 Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 1 minute ago, JoshEir said: what was the problem? The bit I gave you a fix for in my first reply. Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585200 Share on other sites More sharing options...
JoshEir Posted March 18, 2021 Author Share Posted March 18, 2021 Ahh, thank you! How is England? Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585201 Share on other sites More sharing options...
Barand Posted March 18, 2021 Share Posted March 18, 2021 Cold, cloudy, wet and in covid lockdown. Apart from that everything's great. Quote Link to comment https://forums.phpfreaks.com/topic/312323-the-problem-is-superglobals-post-values-are-not-defined/#findComment-1585202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.