-
Posts
30 -
Joined
-
Last visited
Posts posted by JoshEir
-
-
I do want the decimals to work as well. I'm no guru either, but because keyword1 is a variable it won't work with quotes. As far as PHP is concerned This seems to be the last question for my ecommerce site project. Next should be Golang with Javascript again. Please help me succeed.
-
I have the following code which is passing the variables to: SaveProductItems(... unfortunately, the passed values are being set to: "" They do not work with .value or without. I need help please.
$imageID = $_GET['imageID']; $fileID = $_GET['fileID']; $descID = $_GET['bdescID']; $title1 = $_GET['title1']; $productID = $_GET['productID']; $titleID = $_GET['btitleID']; $costID = $_GET['bcostID']; $quantityID = $_GET['bquantityID']; $key1ID = $_GET['bkey1ID']; $key2ID = $_GET['bkey2ID']; $key3ID = $_GET['bkey3ID']; $gKeyword1 = $_GET['gKeyword1']; $gKeyword2 = $_GET['gKeyword2']; $gKeyword3 = $_GET['gKeyword3']; $image = $_GET['image']; $description = $_GET['description']; $cost = $_GET['cost']; $quantity = $_GET['quantity']; $category = $_GET['category']; $string0 = " <p id = \"link1\">product id :$productID</p> <div style = \"background-color:#40e0d0;\" class = \"A\" id = \"$mainDiv\"> <center><h1>Added Record<h1></center></p> <div class=\"container\"> <div class=\"row\" > <div class = \"col\"> <iframe id=\"upload_target\" name=\"upload_target\" style=\"width:0;height:0;border:0px solid #fff;\"></iframe> <div class=\"text-left\"> <form target=\"upload_target\" method = \"POST\" action = \"upload2a.php\" enctype=\"multipart/form-data\"> <input type=hidden id=\"$productID\" name= \"productID\" value=\"$productID\"> <!-- <input type=hidden id=\"$filename\" name=\"filename\" value=\"$filename\"> --> <input type = \"file\" name = \"file\" id = \"$fileID\"> <br><br> <button value = \"Submit\" type = \"submit\" >submit it</button> </form> <div id = \"text-left\"> <button onclick = \"imageRefresh( '{$filename}', '{$imageID}')\" >Confirm</button><br><br> </div> </div> <img class=\"NO-CACHE\" width=\"120\" height =\"120\" id = \"$imageID\" src=\"http://localhost/phpproj/uploads/$filename?<?php filemtime('$filename') ?>\">No Image</img> </div> <div class=\"col\"><br><br><br><br> <h4><center><p id =\"\" >Title</p></center></h4> <center><p> <input id = \"$titleID\" value = \"$title1\" type=\"text\" name=\"\" placeholder=\"\"></p></center> </div> <div class=\"col\"> <h4><center><p id = \"\">Desc</p></center></h4> <center><textarea wrap id = \"$descID\" value = \"$description\" name=\"text\" rows=\"5\" cols=\"34\">$description</textarea></center> </div> <div class=\"col\"><br><br> <h4><center><p id = \"\" >Cost</p></center></h4> <center><p> <input id = $costID value = $cost type=\"number\" name=\"title\" placeholder=\"$cost\"> </p></center> </div> </div> </div> <div class=\"container\"> <div class=\"row\" > <div class=\"col\"> <h4><center><p id = \"\" >Quantity</p></center></h4> <center><p> <input id = $quantityID value = $quantity type=\"number\" name=\"title\" placeholder=\"$quantity\"> </p></center> </div> <div class=\"col\"> <h4><center><p id = \"\" >Keyword 1</p></center></h4> <center><p> <input id = \"$key1ID\" value = \"$gKeyword1\" type=\"text\" name=\"title\" placeholder=\"$gKeyword1\"> </p></center> </div> <div class=\"col\"> <h4><center><p id = \"\" >Keyword 2</p></center></h4> <center><p> <input id = \"$key2ID\" value = \"$gKeyword2\" type=\"text\" name=\"title\" placeholder=\"$gKeyword2\"> </p></center> </div> <div class=\"col\"> <h4><center><p id = \"\" >Keyword 3</p></center></h4> <center><p> <input id = \"$key3ID\" value = \"$gKeyword3\" type=\"text\" name=\"title\" placeholder=\"$gKeyword3\"> </p></center> </div> <br><br> </div> </div> <div class=\"container\"> <div class=\"row\" > <!-- the keys are --> <div class=\"col\"> //////////////////////////////////////////// //////////////////Failing funtion call:////// //////////////////////////////////////////// <center><button id = \"\" onclick = \"SaveProductItems( '{$productID}', '{$deleteFlag}', '{$mainDiv}', '{$titleID}', '{$descID}', '{$costID}','{$quantityID}', '{$key1ID}' , '{$key2ID}' , '{$key3ID}' )\">Resubmit</button></center> <center><button id = \"\" onclick = \"deleteRecord(1, '{$mainDiv}', '{$productID}' )\">Delete</button></center> </div> </div> </div> </div><!--mainDiv--> ";//stringend insertNewRecord( $fileID, $filename, $title1, $descID ,$productID, $titleID ,$costID ,$quantityID,$key1ID ,$key2ID ,$key3ID ,$gKeyword1 , $gKeyword2 ,$gKeyword3 ,$image ,$description, $cost ,$quantity , $category ); if (!isset($myObj) && isset($string0)) { $myObj = new stdClass(); $myObj->htmlstuff = $string0; //Encode the data as a JSON string $jsonStr = json_encode($myObj); echo $jsonStr; }
And here is the Javascript function that sets the values to "" or [object HTMLTextAreaElement.
function SaveProductItems( ProductID, deleteFlag , maindiv, title, desc, cost, quantity, keyword1, keyword2, keyword3){ const element = document.getElementById("dropDown1"); const checkValue = element.options[element.selectedIndex].value; const checkText = element.options[element.selectedIndex].text; var val13 = checkText; //changed these var val1 = document.getElementById(title); var a = val1.value; ////////////////////////////////////////// //////////////PROBLEM HERE:////////////// ///////////////////////////////////////// var val2 = document.getElementById(desc).value; var val3 = document.getElementById(cost); var val4 = document.getElementById(quantity); var val5 = ProductID; var val8 = document.getElementById(keyword1).value; var val9 = document.getElementById(keyword2).value; var val10 = document.getElementById(keyword3).value; //var val11 = document.getElementById(fileID).attributes.value.textContent //var val11 = document.getElementById(fileID).value; //var val11 = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '') //var val14 = category; //var val15 = customerid; if (deleteFlag == 1) { document.getElementById(maindiv).innerHTML = ""; } var xmlhttp = new XMLHttpRequest(); var PageToSendTo = "saveNewRecord.php?"; var UrlToSend = PageToSendTo + "val1=" + val1 + "&" + "val2=" + val2 + "&" + "val3=" + val3 + "&" + "val4=" + val4 + "&" + "val8=" + val8 + "&" + "val9=" + val9 + "&" + "val10=" + val10 + "&" + "val5=" + val5 + "&" + "val13=" + val13 + "&" + /*"filename=" + val11 "&" +*/ "pdib=" + ProductID; xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { } }; xmlhttp.open("GET", UrlToSend , true); xmlhttp.send(); }
Thank you for your help,
JoshEir
-
Ahh, thank you! How is England?
-
That seemed to do it, what was the problem?
-
I just updated.
-
Oh,
Array ( [1439] => 1439 [A5_png] => A5.png )
-
Well, as you can see the action is that, however there is an iframe. Any clue?
-
The response is Array()
-
Still doesn't work, its odd.
-
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'];
-
I am having trouble with my phone to set up pay pal. I'll get to it soon.
-
Thank you, I would never have suspected that! Hence, this error reporting is important, is it an extension? I'm using Visual Code.
Josh
-
I'd love to use anonymous placeholders on my ecommerce site project. I am writing half with php and half with golang. On the three examples below, when run, gives the following exception, " Error: Call to a member function execute() on string. " I tried it with a decimal too. Thanks in advance.
$stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->execute(); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->bindParam(1, $productID, PDO::PARAM_INT); $stmt->execute(); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); //this one calls exception $stmt->bindValue(1, $productID, PDO::PARAM_INT); $stmt->execute();
Here is the rest of the code :
<?php $filename = ""; $keyword1 = $_GET['keyword']; $titleOfSelectedDropDown = $_GET['val1']; $fileID = ""; $imageID = "a"; $displayID = ""; $keyword1 = "test"; $titleOfSelectedDropDown = "cc"; $host = 'localhost'; $user = 'root'; $pass = ''; $database = 'ecommerce'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $gKeyword1 = ""; $gKeyword2 = ""; $gKeyword3 = ""; $key1ID = ""; $key2ID = ""; $key3ID = ""; $string1 = "<center><h1><u>Search Results</u><h1></center></p>"; $dbo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $stmt = $dbo->prepare = ("SELECT * FROM products WHERE ProductName = ?"); $test = "1"; $stmt->execute([ $test ]);
-
Thanks for your help, I had never created my own div before, making them dynamically. I just completed the Administrator's product system. For the rest, I plan to use modern PHP instead of the Vanilla variety.
Josh
-
May the DIV ID be a variable or does it need to be known in advance with a real id?
-
I'm trying to write an ecommerce site and was doing well until this one. It has has taken me a few days...can't get it. It won't display answerHtml in the pear div using a string. The idea is to use a variable for the pear div and to place apple div into it. The error is : fails with cannot set property 'innerhtml' of null .
html> <body> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var jsonData = JSON.parse(this.responseText); var answerHtml = jsonData.htmlstuff; var pear1 = jsonData.div; //fails with cannot set property 'innerhtml' of null document.getElementById(pear1).innerHTML = answerHtml; } }; xmlhttp.open("GET", "div2.php", true); xmlhttp.send(); </script> </body> </html>
<?php $host = 'localhost'; $user = 'root'; $pass = ''; $database = 'ecommerce'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $dbo3 = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $var = "pear"; $string = " <div> <div id = \"$var\" >here </div> <div id = \"apple\"> <button type=\"button\" onclick=\"loadDoc()\">Change Content</button> </div> </div> "; $myObj = new stdClass(); $myObj->htmlstuff = $string; $myObj->div = $var; //Encode the data as a JSON string $jsonStr = json_encode($myObj); echo $jsonStr; ?>
Thank you for your time.
-
I am playing with PHPStorm and Visual Code at the same time. I finally got Visual Code working again, the program. PHPStorm won't set me back, I think it is a good price at around nine dollars a month with a month to consider.
Using Visual Code for PHP and JavaScript I can run in parallel which is nice. However, I am having problem with the red JavaScript breakpoint turning to a grey outlined breakpoint after Chrome is launched. The debugger doesn't stop there.
Using Chrome Developer Tools doesn't seem to be an option for me because It doesn't seem possible to access more than one page to debug with breakpoints.
Do you understand it the same way?
Josh
-
I am trying to find a good IDE for PHP and JavaScript. I fiddled around with Visual Code and it was very buggy. The GitHub page said over 800 open errors?!?!? Now I'm looking at PHPStorm and it reads that only PHP in a PHP page or JavaScript in a JavaScript page may be debugged. I am wondering if this is always possible to separate the code like this.
Also, in the following code, what do you all think about using a XMLHttpRequest() to call this right in the beginning of the page with no button or anything. Is this bad form? It creates a dropdown list from the database. Right now it just sits there. This code isn't ready for prepare yet.
<?php $host = 'localhost'; $user = 'root'; $pass = ''; $database = 'ecommerce'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $dbo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $q4 = "SELECT categories.title FROM categories INNER JOIN customers on customers.CustomerID = categories.CustomerID and customers.CustomerID = 1"; echo '<select id = "dropDown1" >'; foreach ($dbo->query($q4) as $row) { echo "<br>"; echo '<option value = " '; echo $row['title']; echo '">'; echo $row['title']; echo '</option>'; } echo "<br>"; echo '</select>'; ?>
I'm using AJAX.
-
Tutorials sound smart. Someone said PHP takes 6 months to learn. This is what helped me do the prepare with PDO : https://phpdelusions.net/pdo. I got it working pretty quick.
-
Thanks for the links, I'll look at them next. This is what happened. I was quite mad from a hard to find bug with Visual Code. Something else happened with it that convinced me the only way to be is to download code that has cost. So, I was working with Sublime editor and Wamp server when the error, in question, was found.
Now the reason for the the unfinished code I submitted was because I thought the foreach was failing because there was no record and what I was looking for was a way to count the rows and break if there weren't any records. I couldn't find the bug, so I decided to use Visual Code again because I was having just as much problems using Sublime editor.
Low and behold, I found the bug quickly, and you were right that the error would help, because it did! When there was no record it was throwing an exception because my string of html data was undefined because it was in the foreach.
So the moral of the story is, bugs really do help you find problems, Visual Code is fine, and it is fine to use free software.
-
Oh, thanks, could you recommend what way to go that has plenty of instructions. For example, I was using PDO.
-
Google Chrome Developer Tool causes an error when I run the following and there are not any records. I keep getting errors when I try to change it.
<?php $host = 'localhost'; $user = 'root'; $pass = ''; $database = 'ecommerce'; $options = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false ); $keyword = $_GET['keyword']; $dbo = new PDO("mysql:host=$host;dbname=$database", $user, $pass, $options); $q1 = "SELECT * FROM products INNER JOIN keywords on keywords.keywordID = products.KeywordID and keywords.KeyWord1 = \"$keyword\" "; $counter = 10; $counter1 = 0; foreach ($dbo->query($q1) as $row) {
-
It would be harder to read though with all the quotes, breaking and continuing, with the database data.
-
I've been working on JSON and have found a way to send variables from the PHP to the JavaScript using AJAX and no JQuery. For an ecommerce site does it make more sense to send the variables : description, title, cost, etc. to the JavaScript page, or would it make more sense to echo the html on the PHP page? The idea, right now, is a product page for editing and deleting product.
Thanks,
Josh
Can't get a real value with: document.getElementById(keyword1).value;
in Javascript Help
Posted
Well, I have narrowed down the code so that it is evident that it is in the html string. Because of this, I should be able to find the bug,
Thanks!