Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Everything posted by gbengasupowale807

  1. Please, who have any resources on twig and doctrine ORM should please share me links
  2. Am trying to put mysqli result set into an array for later use and this is how I did it(but is not working) $split = []; $sql_money = "SELECT j_id, amount_invested FROM j_members WHERE j_activated = 1 LIMIT 5"; $result_money = mysqli_query($conn, $sql_money); while($data = mysqli_fetch_assoc($result_money)){ $split[] = ['id' => $data['id'], 'invest' => $data['amount_invested']]; //echo $data['j_id']; } foreach($split as $s){ echo $s['id'] . '<br>'; } Who can put me through
  3. I wrote a forum app sometimes ago and am trying to improve it . I have an issue that is hard for me to solve(I don’t even know how to solve it, I just have the idea), how can I create a notification menu like the one on this site, sitepoint, stackoverflow etc that display at the top of the menu for a user about messages that were received on thread or post he start or comment on. The forum was created using PHP
  4. I have surf the web but still don’t find an explaining tutorial on how to use either google map or php google map to automatically detect the location of a user. This is what I want to achieve, during registration, a user current location will be extracted using either the js version of the map or the php version(depending on the one I saw a good way of using it), and extraction, the current town or city or village with also the country. Who can really put me through on how to use any of the above library
  5. Since the 2nd edition of the book was lunched some years ago, there have been changes in authorized.net form. I believe a section should be dedicated for the implementations of all the payment gateways used in the book
  6. Sir I don't know if you can give us an update on the gateway api as much has change since the time you did the last update
  7. yes. I have forgotten the the message. But it shows 200(meaning ok). But what baffles me is that instead of testify.js to show that POST is being used, it says GET while the testify.html shows POST.. Sorry for late response
  8. (Using the example in Modern javascript) Am trying to submit data for processing and insertion into the database using php but it could not work and I don't why and these are the steps taking so far. 1. Using php alone, am able to insert data into the database an d this is the php code. <?php try { $linkas = 2; require_once 'db/DBConnect.php'; $errors = []; $good = true; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['testimony'])): $testimony = filter_input(INPUT_POST, 'testimony', FILTER_SANITIZE_STRING); if (strlen($testimony) < 20): //report error and do not go $errors[] = 'It has to be more than 20 characters' . '<br>'; $good = false; else: $good = true; if ($good): $insertTestimony = 'INSERT INTO testimony(content, j_member_id, time_send) '; $insertTestimony .= 'VALUES (:testimony, :user_id, NOW())'; $insert = $conn1->prepare($insertTestimony); $insert->bindValue(':testimony', $testimony, PDO::PARAM_STR); $insert->bindValue(':user_id', $linkas, PDO::PARAM_INT); $insert->execute(); if ($insert->rowCount() == 1): //success message $_SESSION['msg'] = 'Thanks for the testimony'; header('Location: index.php'); exit(); else: //fail message echo 'Something is wrong, please resubmit'; endif; endif; endif; endif; } catch (Exception $e) { echo 'Database error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } ?> After testing the php and seeing that it works, I proceeded to create the html page which is below <html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <section class=""> <article> <div id="testifyForm"> <form action="" method="post" id="testimony" accept-charset="utf-8"> <fieldset> <legend>Your testimony</legend> <label for="testimony"></label> <textarea id="testimony" name="testimony" maxlength="300"></textarea> </fieldset> <input type="submit" name="testify" id="testify" value="Testify"> </form> </div> </article> </section> <script src="js/ajax.js"></script> <script src="js/testify.js"></script> </body> </html> Finally, I created the ajax.js script and testify.js script and placed them inside the js folder and link them to the html which you can see above. This is the testify script function validateForm() { 'use strict'; var testimony = document.getElementById('testimony'); if ((testimony.value.length > 20)) { var ajax = getXMLHttpRequestObject(); ajax.onreadystatechange = function () { if (ajax.readyState == 4) { if ((ajax.status >= 200 && ajax.status < 300) || (ajax.status == 300)) { //return ajax.responseText document.getElementById('testifyForm').innerHTML = ajax.responseText; } else { document.getElementById('theForm').submit(); //return ajax.statusText }//End of status ajax = null; }//End of readyState };//End of onreadystatechange //return true; ajax.open('POST', 'empty.php', true); ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var data = 'testimony=' + encodeURIComponent(testimony.value); ajax.send(data); return false; } else { document.getElementById('error').innerHTML = 'Characters must be more than 20 words'; return false; }//End of testimony } function init() { 'use strict'; if (document && document.getElementById) { var testifyForm = document.getElementById('testifyForm'); testifyForm.onsubmit = validateForm; } } window.onload = init; And this is the ajax script function getXMLHttpRequestObject() { var ajax = null; if (window.XMLHttpRequest) { ajax = new XMLHttpRequest(); } else if (window.ActiveXObject) { // Older IE. ajax = new ActiveXObject('MSXML2.XMLHTTP.3.0'); } return ajax; } The problem now is that ajax refuses to submit those data for processing and saving(which I believe PHP should handle). I also tried debugging it if there is any error by checking the console with ctrl+shift+j on chrome(that is the only step taken so far about debbuging) P.s. This is pure JavaScript and ajax not jquery
  9. This codes works on local server(XAMPP) but does not seems to work on live server. And I can't really figure out what the problem is since there no error is output in the errorlog. In the script, I tried to use the--pre--tag but also nothing gets displayed <?php session_start();?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Testimony</title> </head> <body> <?php try { $linkas = 2; require_once 'db/DBConnect.php'; $errors = []; $good = true; if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['testimony'])): $testimony = /*filter_input(INPUT_POST, 'testimony', FILTER_SANITIZE_STRING)*/$_POST['testimony']; echo $testimony; if (strlen($testimony) < 20): //report error and do not go $errors[] = 'It has to be more than 20 characters' . '<br>'; $good = false; else: echo $testimony; $good = true; if ($good): $insertTestimony = 'INSERT INTO testimony(content, j_member_id) '; $insertTestimony .= 'VALUES (:testimony, :user_id)'; $insert = $conn1->prepare($insertTestimony); $insert->bindValue(':testimony', $testimony, PDO::PARAM_STR); $insert->bindValue(':user_id', $linkas, PDO::PARAM_INT); $insert->execute(); if ($insert->rowCount() == 1): //success message //$_SESSION['msg'] = 'Thanks for the testimony'; header('Location: index.php'); else: //fail message echo 'Something is wrong, please resubmit'; endif; endif; endif; endif; } catch (Exception $e) { echo 'Database error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine(); } ?> <section class=""> <article> <form action="" method="post" id="testimony" accept-charset="utf-8"> <fieldset> <legend>Your testimony</legend> <label for="testimony"></label> <textarea id="testimony" name="testimony" maxlength="300"><?php if (isset($_POST['testimony'])): echo htmlspecialchars($testimony); endif; ?></textarea> </fieldset> <input type="submit" name="testify" id="testify" value="Testify"> </form> </article> </section> </body> </html> And this is the database connection string which I used to connect to the database and its located inside the db folder <?php //Db connection 1 $username ="XXXXX"; // censored for SO $password = "XXXXX"; // censored for SO //$database = "xzelanet_180days"; //$server="localhost"; $conn1 = new PDO('mysql:host=localhost;dbname=xzeere_30days; charset=utf8', $username, $password); $conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); After the form submission, the form refuses to insert into the database(the form displayed but does not submit[i think the problem should be inside the code processing the form])
  10. getXMLHttpRequestObject returns nothing, which means it returns undefined. The ajax variable inside that function is not the same as the one outside. So I have to return variable ajax at the end of both functions. window.onload = function(){ 'use strict'; var ajax = getXMLHttpRequestObject(); ajax.onreadystatechange = function(){ if(ajax.readyState == 4){ if((ajax.status >= 200 && ajax.status < 300) || (ajax.status == 304)){ document.getElementById('output').innerHTML = ajax.responseText; }else{ document.getElementById('output').innerHTML = 'Error ' + ajax.statusText; } } }; document.getElementById('btn').onclick = function(){ ajax.open('GET', 'resources/test.txt', true); ajax.send(null); }; //return var ajax **return ajax;** } function getXMLHttpRequestObject(){ var ajax = null; if(window.XMLHttpRequest){ ajax = new XMLHttpRequest(); }else if(window.ActiveXObject){ ajax = new ActiveXObject('MSXML2.XMLHTTP.3.0'); } //return var ajax **return ajax** }
  11. Uncaught TypeError: Cannot set property 'onreadystatechange' of undefined at window.onload (test.js:4). The above error message is what is displayed on the console while trying to run the ajax example on page 433 of the book. What can be done to rectify it? Any clue or answer will be appreciated.
  12. Am happy you are the one who replied me sir. What is SSH and how connect to the server via SSH?
  13. I don't know if anybody can put me through how to install composer on live server as I find little or no success at all on the net about how to do it
  • Create New...