Jump to content
Larry Ullman's Book Forums

sonal

Members
  • Content Count

    121
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by sonal

  1. As I'm exploring web development, I found wordpress interesting, popular and "need to know" kind of thing. So, far I come to know about different themes and how to set up it among other basic stuff. I like to know : 1. How to I know where I need to change PHP code? I mean which file for what purpose? I know there is lot of WordPress tutorials and resources around there, but it is overwhelming and making me more confused. 2. I see posts filed under series on this site. Like there are Yii series, jQuery series and more. How do I collect posts filed under different categories and then show them as series? Sonal
  2. I want to add a modal window (created with css and javascript) to pop-up a form when a user clicks "add quote" button on one of my php script. I have created a form in q1.html file, with required div settings. There is a modal.css file as Larry has given in the book. This html file on its own shows a poping up modal window with it's own "show window" button. Now, I want to include this html file in one of the php script. If I use a link with <a href" tag pointing to q1.html file, it opens up in an entire new window. That is of no use to use a poping up modal form. If I use "include('q1.html') file in php, the form stops working. The modal.css applies to the main page where I'm including this file. SO, how do I do it? I think the problem comes from DOM, as modal.js file asks for elements in html file. But I don't understand how to resolve it. I was searching on Internet, and all of it returns jquery solutions. At this point I don't want to use jqueary, as I want to learn javascript first. thanks
  3. Hi HartleySan, thanks for your suggestion. I did what you said (combine all different stuff into one file, making a new function for each task). AND MAGIC.. it's working, as I expected it to work. Good.. I like all these stuff about js, ajax and php really much.. But I would like to know, what of my code seems a bit odd? Will you please share your looks/concerns or anything that I'm doing wrong in above code? Thanks again..
  4. It is necessary to run your ajax script through a server. Larry has explained it like this, "If your request is returning a 0 status code, you probably are not making the request through a URL. I hope that's what where the problem is coming from in your case...
  5. I thought so. I should explain in detail what I'm upto. I want to display "quotable quotes" on index page. To do that I'm fetching quotes through ajax and putting that js script into my "header" html page. code for that: /* * return json data from quotelist.php using ajax. * */ window.onload = function() { 'use strict'; var quoteDisp = document.getElementById('qquote'); var jAjax = getXMLHttpRequestObject(); //This is defined in another file. Which is working nicely. jAjax.onreadystatechange = function() { if(jAjax.readyState == 4) { if((jAjax.status >= 200 && jAjax.status < 300) || (jAjax.status == 304)) { var output = jAjax.responseText; //alert(output); document.getElementById("qquote").innerHTML = output; } else { //alert("Error" + jAjax.statusText); } } }; //End of onreadystatechange anonumous function. jAjax.open('GET', 'quotelist.php', true); jAjax.send(null); }; //first form to display book names by title. It shows autolist as user keys in title, and then displays a book details selected from the list. Following two files are included on index page through a "main.php" script, which shows different pages collected by index page. I hope this makes sense. This scripts are online at www.myreadinglog.net. Although the front page shows only quotes displayed on left side bar under "quotable quotes". Two other forms can be seen by a logged in user only. both of php scripts return XML data. //functio to handle ajax response: function handleAjaxResponse(e) { 'use strict'; if(typeof e == 'undefined') e = window.event; var ajax = e.target || e.srcElement; if(ajax.readyState == 4 ) { if ((ajax.status >=200 && ajax.status < 300) || ajax.status == 304) { if(ajax.responseXML) { //display result. } } function sendValue() { var searchTerm = document.getElementById('searchTerm'); searchTerm = searchTerm.value; if(searchTerm.length > 3) { var ajax = getXMLHttpRequestObject(); ajax.onreadystatechange = handleAjaxResponse; //ajax.open('GET', 'isbn31.php?searchterm=' + encodeURIComponent(searchTerm.value), true); ajax.open('GET', 'isbn31.php?searchterm=' + encodeURIComponent(searchTerm), true); ajax.send(null); // return false; } } window.onload = function() { 'use strict'; U.addEvent(document.getElementById('searchTerm'), 'keyup', sendValue); //addEvent function is in a separate file under U object, works fine. } Third script for second form file. It displays book details fetched through ISBN. Only one result is returned and displayed using ajax. function getData(e) { 'use strict'; if(typeof e == 'undefined') e = window.event; var Iajax = e.target || e.srcElement; Iajax.onreadystatechange = function() { if(Iajax.readyState==4) { if((Iajax.status >= 200&& Iajax.status<300) || (Iajax.status==304)) { if(Iajax.responseXML) { //display result } } } function sendVal() { var IsearchTerm = document.getElementById('searchterm'); IsearchTerm = IsearchTerm.value; var Iajax = getXMLHttpRequestObject(); Iajax.onreadystatechange = getData; Iajax.open('GET', 'newisbn.php?searchterm=' + encodeURIComponent(IsearchTerm), true); Iajax.send(null); // return false; } window.onload = function() { U.addEvent(document.getElementById('searchterm'), 'blur', sendVal); U.addEvent(document.getElementById('isbn'), 'blur', sendVal); U.addEvent(document.getElementById("isbn"), 'submit', sendVal); }
  6. Thanks a lot, HartleySan for your reply. Although, I have used different ajax objects in both forms they don't seem to work together. Still the problem is as it is. Each html file works great individually, but when I keep both of them on the same page, only one of it works. I also have included third js-ajax-php script on the same page. So, now this one works and the other two stopped working. How do I do that?
  7. I have two forms on my index page. Both of these forms uses ajax to fetch and display data on the page from different php scripts. Both works great individually, showing results as expected. But, when I put both of them at the same time one of them is not showing resulting data. I have used addEventListener in my javascript to add events and my ajax part of both scripts use ajax.send(null) at the end of a function sending data off to php. What can be the problem? What am I missing? thanx in advance
  8. I see examples how to fetch data from php to ajax (and display it via javascript.) As in log-in example, we can check whether there is a valid email and password entered, we can simply display "You are now logged in." Till here I understand and work out. But, now as the user logs in, I need to set the php session. The login form sends data to the ajax.php, which simply returns a success message. In other case, if I just use php to check valid login details, I can set php session as soon as the script finds match data. I know I can send ajax data through URL to second php page, where it can access through $_GET. But I want to get that data into SESSION rather than sending through URL. How I do that?
  9. First I would like to know how to plan in terms of developing the code. (Ok, so now I know there are 2 different things when it comes to plan.) Thanks
  10. May be this is an old question. May be I read something about website development planning in one of the Larry's newsletter. But, I don't remember it now. I really want to know in detail, up to the advanced level, how to plan a website? As well as, about the blog. Is this site, Larryullman.com, a website or a blog? I know the subject for my blog. So that brainstorming is kind of done. What things should I know if I plan a long-term, successful blog where I myself can keep interest of posting new entries? Now, I that I'm learning about website development technology since a year, I can write many different kind of things. So I keep doing little animations, form validations, AJAX techniques in Javascript, various php-database interactions and so on. But, I still need to know what do I do to make a good blend of all these html, css, javascript, php-database things? Hope to hear from you all. Thanks
  11. As far as I understand this case is something like : parseInt function is used to show how to convert randomly generated float numbers to integers, as random.js shows use of for loop. volume calculator uses if(isNan(volume)) condition to check whether the incoming value is valid number, to show if-else if conditionals. If a value is coming from text input, it may be treated as a number or a string. There is no guarantee that if you enter a number in a text type input it will treated as a number all the time. It is better to use parseInt or parseFloat function while making numeric calculations. I had this problem in one of my form, that numbers were not compared correctly before I used parse functions. May be this is different if we use number type text input for HTML5 form elements.
  12. I got it corrected. a, b and c values were coming from text type form fields. So they were comparing as strings rather than numbers. I had to use parseInt function to convert them to numbers before comparing them. That is a simple example to show how to use nested if. Thanks for looking....
  13. What is wrong with following neseted if conditions? This program shows wrong result to compare 3 integer numbers and find out maximum number. I'm so confused. This program gives a wrong maximum number. var a = prompt("Enter first number"); var b = prompt("Enter second number"); var c = prompt("Enter third number"); var answer; document.getElementById("no1").innerHTML = "a : " + a; document.getElementById("no2").innerHTML = "b : " + b; document.getElementById("no3").innerHTML = "c : " + c; if(a > { if (a > c) { //alert("a is maximu : " + a); answer = a +" a is maximum"; } else { //alert("c1 is max : " + c); answer = c + " c1 is maximum"; } } else { if(b > c) { answer = b +" b is maximum"; } else { //alert("c2 is maximum : " + c); answer = c + " c2 is maximum"; } } document.getElementById("show").innerHTML = answer;
  14. I was also looking at this question. May be there is an answer at this page : http://codex.wordpress.org/Post_Types I haven't been able to try it myself yet.
  15. oh, ok. here 'Quote' is a simple string (quotable quotes like thing). (I have kept its length from 20 characters to 800 alphabetic characters.)
  16. Does following form validation done in the right order? Do I need all of it? Or are these just extra lines of code? if(isset($_POST['quote']) && is_string($_POST['quote'])) { //to check data is filled. //sanitize incoming quote: if(preg_match('/^[A-Z \'.-]{20,800}$/i', $_POST['quote'])) { //reg exp will check only allowed characters are present. $_POST['quote'] = filter_var($_POST['quote'], FILTER_SANITIZE_STRING); //same as reg exp?? $_POST['quote'] = filter_var($_POST['quote'], FILTER_SANITIZE_SPECIAL_CHARS); //reg exp won't let come here..?? $_POST['quote'] = mysqli_real_escape_string($dbc, trim($_POST['quote'])); } //if(preg_match['quote'].
  17. I got the error. There was a primary key violation in my query, so the second row was never inserted. Got it solved!!
  18. Following script inserts only one (first iteration) record. For next iterations, mysqli_stmt_execute never works. Why? $dbc = database connection //just to shortan the script here $mid[] = {1,2,3,4}; //to short out the script here. $q5 = "INSERT INTO user_book_trn(user_id, member_id, book_id, date_read, lang_id) VALUES (?, ?, ?, now(), ?)"; $s5 = mysqli_prepare($dbc, $q5); //Bind the variables: mysqli_stmt_bind_param($s5, 'iiii', $user_id, $member_id, $book_id, $lang_id); foreach($mid as $mk => $mv) { echo "member id value : $mv \n"; $q2 = "SELECT user_id, member_id, book_id from user_book_trn where user_id = {$_SESSION['myuser']['userid']} and member_id = {$mv} and book_id= {$w}"; $r3 = mysqli_query($dbc, $q2); if (mysqli_num_rows($r3) == 0) { //title is available for this user. //Assign the values to variables: $user_id = (int)$_SESSION['myuser']['userid']; $member_id = (int)$mv; $book_id = (int)$w; $lang_id = (int)$_SESSION['lid']; //just to check each iteration gets new values: echo "user_id : $user_id \n"; echo "member_id : $member_id \n"; echo "book_id : $book_id \n"; //Execute the query: mysqli_stmt_execute($s5); if(mysqli_affected_rows($dbc) == 1) { //If it ran OK.. echo "<p><b> The book $t is added. </b></p>"; $_SESSION['bookid'] = $book_id; } I'm using prepared statements as they are more secure. Is this the right way to use it?
  19. Thanks Larry, I appreciate your input here. It makes me more comfortable in my work..
  20. As I read Larry's book, Modern JavaScript, I know it is no good to use document.writeln method to print any data in the browser. Now, I wanted to teach programming to kids using JavaScript. I just want them to learn fundamental programming skills like, conditionals and loops without getting into details of DOM and other things. So, what is the best approach/method/function to use with JavaScript that prints out data on the browser? I want to use JavaScript for following reasons: 1. We don't need any extra softwares. 2. Any student knows what is a website, and what they can expect there. 3. Students can understand what they are doing, because they can see the results instantatly. This is my own experience. When I studied C and C++, I never understood why I'm "typing" all these mysterious characters just to add 2 numbers. But, now when I do PHP and JavaScript programming, I very well understand what I'm doing and what I need my program to do. So far, I'm going with document.write method, but want to know better ideas.
  21. I have a script that fetches XML data through PHP (books.php). Another script, view.js with AJAX and Javascript is used to display the result from books.php. Now I want to send some data like book_id, author_id etc to next PHP script through either url or in a session. books.php simply echos out XML data in one string format, which then is manipulated in view.php. books.php 02 03 header('Cache-Control: no-cache'); 04 header('Content-Type: text/xml'); 05 //echo '<?xml version="1.0" encoding="utf-8" standalone="yes" 06 //<item>'; 07 08 $stitle = $_GET['searchterm']; 09 $stitle = urlencode($stitle); 10 //echo $stitle; 11 12 $url = "books.xml?value1=" .$stitle; 13 14 $xml = file_get_contents($url); 15 16 echo $xml; 17 18 //If I manipulate xml file here, and get data into separate variables to send them to next php script, then it messes up javascript file view.js, which uses ajax to read the xml doc. ?> view.js uses ajax to read that xml document and print the data in web page. This data then I need to send to next php script.
  22. I have following update statement in one of the script, and it is not working. I tried to debug as much as I can without success. What can be the problem? $rating = 4; $q = "UPDATE user_book_trn SET book_rating = ? WHERE user_id = 1 AND member_id=24 AND book_id=120"; $r = mysqli_prepare($dbc, $q) or trigger_error("Query: $q\n<br />" . mysqli_error($dbc)); mysqli_bind_param($r, 'i', $br); $br = (int) $rating; //echo "\n rating : " . $br; mysqli_stmt_execute($r); if(mysqli_stmt_affected_rows($r)==1) { echo "Thanks for submitting your rating for the book. We appreciate it!"; } else { echo "error"; echo '<p>' . mysqli_stmt_error($r) . '</p>'; } The query runs OK in phpmyAdmin with the given values and also for other values in tables. But this script always prints "error" message, but never shows any mysqli_stmt_error.
  23. ../ to get out of the current directory and reach to the home directory. home folder contains includes and www folder. And then, includes folder contains header and footer file. Other 3 files are in www folder. That's my file structure, which is not showing in the figure.
  24. I read that, $_SERVER['DOCUMNET_ROOT'] identifies the document location.
  25. I have following file structure : home ---- .----- includes folder . ------- header file ------ footer file ----- www folder ---- index.php file ---- submit.php file ---- articles.php footer file includes file like this : include("../www/articles.php"); index and submit file includes files like these: include("../includes/footer.html"); articles.php does not include header and footer, as it itself is included inside footer.html. (articles list are shown on each page.) Now, index file shows correct formatting and output. But, submit page shows error including articles.php. So, how do I make the relative path over here? What am I missing understanding things about relative paths?
×
×
  • Create New...