Jump to content
Larry Ullman's Book Forums

All Activity

This stream auto-updates     

  1. Last week
  2. I think you're missing an equals sign. This code-- if (mysqli_num_rows($r) = $username) { --is trying to assign the value of $username to mysqli_num_rows($r), which of course isn't possible. You want == $username instead. But that still won't work because mysqli_num_rows() is going to return an array and what you need to do is compare an element in that array to $username.
  3. Sorry about the double posting above. I was hoping to delete my original post so I could correct it. The error message refers to line 137 not 37. Anyway, the original code I used came from the first edition of the eCommerce book which uses "rows". So the original code would have written <p><h2>Hello $row[1]!</p>.
  4. I have been updating a website with the scripting from this book. A piece of code I have is not working with the new php and I have reworked this several times. The following is the error message that I get in the server error log - PHP Fatal error: Can't use function return value in write context in /hermes/bosnacweb04/bosnacweb04aj/b717/nf.xxxxxxxxx/public_html/xxxxxxxx.com/Login.php on line 137 Line 37 would be the following - if (mysqli_num_rows($r) = $username) { <?php // Show the user info or the login form: if (isset($_SESSION['user_id'])) { // Show basic user options: $q = "SELECT user_id, username FROM users WHERE user_id={$_SESSION['user_id']}"; $r = mysqli_query ($db, $q); //if (mysqli_num_rows($r) > 0) { if (mysqli_num_rows($r) = $username) { //while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { while ($r = mysqli_fetch_array($r, MYSQLI_NUM)) { // Display the username and heading echo "<p><h2a>Hello $username!</p>"; } } Thanks
  5. sam

    Good book for HTML and CSS

    Too late to help OP - sorry, I've only recently joined the forum - but in case it's of use to others, I've found LEARNING WEB DESIGN by Jennifer Niederst Robbins (O'Reilly, now in its 5th edition) to be an excellent book. Very thorough introduction. The sort of book you can read and keep as a reference.
  6. While the code you posted did not come from PHP for the Web Fourth Edition, I found this code helpful for the eighth task quoted below in the Pursue section at the end of Chapter 3 from the Fourth Edition. I was curious how much fuel will cost for an upcoming trip to Texas. Thanks for posting the code!
  7. You'll just need to use the mail() function. You can learn all the details and see examples in the PHP manual: http://php.net/manual/en/function.mail.php
  8. Ah, excellent find and fix! Kudos for figuring that out and thanks for sharing the solution!
  9. Earlier
  10. Thankyou very much Larry for the reply and guidance. I did try the lowercase and stricmp, but it did not work. I did find a solution though and the reason for the problem. I could not have done it without your help and support! THANKS V. MUCH! Problem: Now Paypal IPN sends back VERIFIED but with numbers before and after Solution: Change the function : if (strcmp ($res, "VERIFIED") == 0) { To if (strpos($res,'VERIFIED') !== false) {
  11. HartleySan

    Chapter 5 Calculator

    John, we talked about this in your last post, but you cannot do mathematical addition on strings. Whenever you do .value on a DOM form input, you are going to get a string back, even if it looks like a number. That will always be the case. And when you start trying to do fancy math with strings, you'll almost always end up with NaN (or not-a-number). NaN is not a syntax error, that's a logic error in that you're trying to do number math with strings. Please fix that problem and you should be okay.
  12. Yes, you're on the right path. And the concepts are a bit confusing. Remember that cookies are sent back and forth between the server and the browser. The $_COOKIES array is populated by the browser sending cookies back to the server. On the login page, the PHP script sets the cookie which means the cookie doesn't exist when the page is first loaded (i.e., it's not sent from the browser to the server upon login submission). So the logic has to factor in that the login page DOESN'T have the cookie, despite actually setting the cookie. Conversely, the cookie exists on the logout page when the page is first loaded but is then deleted (i.e., the cookie is sent from the browser to the server when accessing the logout script). This means the logic has to factor in that the cookie DOES exist upon first running the page. It probably also helps to remember that the includes become part of the page that included them. So when login.php is run without receiving a cookie from the browser, the included file also don't receive that cookie. (In other words, the execution of the included file is not a separate request from the browser.)
  13. It looks like PayPal is now using the lowercase "verified" for the payer_status. You could switch to that or use stricmp() instead.
  14. Hi Larry, i have few fields in form, like Name: Email: Mob: Address: Query: I want to send all info on my gmail account, please suggest how to do that, there is not much info on emails in the book, (PHP for the web). This is a kind of contact form. I want to send cc and bcc also on my pop3 accounts, my hosting server is host gator in Texas.
  15. Hi Larry: Thankyou very much for making the time to look into my log file. I did what you suggested and figured out the problem. If I remove the following 'if' condition, everything works fine. if (strcmp ($res, "VERIFIED") == 0) Any suggestions as to how I can still use this 'if' condition and keep everything working? Could this be because of the new headers now required by paypal: $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Connection: Close\r\n"; $header .= "Host: www.sandbox.paypal.com\r\n\r\n"; Thankyou once again for your help and support.
  16. there is a function isadministrator() in an includes file which checks for the existence of a certain cookie, yet in the footer there are exceptions in his logic for the login and logout page. can someone please go over with me why its not working on these two pages: on login.php : basically when the pass and user is correct the server sends a cookie to the client but its not available to be read right away unless you refresh the page? on logout,php: destroys the cookie by setting it to false and its time in the past… so then why wouldnt isadministrator work? why does the browser still think the cookie exists? is this the same reason as on login.php page?
  17. There shouldn't be. Part of the point of paying for a web host is they should have this stuff set up and working for you.
  18. Hi HartleySan thanks for replying to my post. I have been recently updating my code and it seems like I got some things to work but there are other parts of the assignment I'm still having trouble with. You may have read in my previous post that I had trouble displaying the error message for when invalid values were entered, I updated my code so now whenever I type an invalid value my paycheck calculator displays the error message like it should. I also found it helpful to create my if then else statement after declaring my variables. Where I'm having trouble now is in Step 3 f where the assignment asks me to create an if then else statement to determine regularHours and overtimeHours wherein Hours Worked over 40 are Overtime Hours and Hours Worked between 0 and 40 are Regular Hours. In addition to this when I press the submit button on my calculator the form values for grossPay, totalTaxes, and netPay all display NaN. I have posted my code down below, I believe the reason my code isn't working is because there might be a syntax error or logical error in my if then else statement and if that's the case I may need to figure out how to rewrite my if then else statement. Thank you once again for responding to my post and any help is appreciated. function calculate() { 'use strict'; var regularPay var overtimePay var hoursWorked = document.getElementById('hoursWorked').value; var regularHours = document.getElementById('regularHours').value; var overtimeHours = document.getElementById('overtimeHours').value; var hourlyRate = document.getElementById('hourlyRate').value; var ficaTax = document.getElementById('ficaTax').value; var stateTax = document.getElementById('stateTax').value; var federalTax = document.getElementById('federalTax').value; var grossPay = document.getElementById ('grossPay').value = parseFloat(+regularPay+ +overtimePay).toFixed(2); var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(+ficaTax+ +stateTax+ +federalTax)* grossPay /100 .toFixed(2); var netPay = document.getElementById ('netPay').value = parseFloat(grossPay-totalTaxes).toFixed(2); var employeeName; var firstName = document.getElementById('firstName').value; var lastName = document.getElementById('lastName').value; employeeName = firstName + ' ' + lastName; document.getElementById('employeeName').value = employeeName; if ( (hoursWorked >= 0 && hoursWorked <= 80 && hourlyRate >= 0 && hourlyRate <= 100) ) { } else { // Show an error: alert('Please enter valid hours and a valid payrate!'); } if ( (hoursWorked > 40) ) { document.getElementById('overtimePay').value = parseFloat(overtimeHours*(hourlyRate*1.5)).toFixed(2); // display overtimeHours: } else if ( (hoursWorked >= 0 && hoursWorked <= 40) ) document.getElementById('regularPay').value = parseFloat(regularHours*hourlyRate).toFixed(2); { // display regularHours: return false; } // end of else } // End of function. function init() { 'use strict'; document.getElementById('form1').onsubmit = calculate; } // End of init() function. window.onload = init;
  19. Created a contact form based on all the forms instruction you've provided. On page 650 you talk about setting SMTP. My web host had a setting of "localhost" and "port 25" so there was an error. They opened a ticket so they could put the proper mail server address in their php.ini (I wonder why it wasn't set properly in the first place). You talk about restarting the server after making the setting change. It seems that a client/user couldn't fix php.ini himself anyway, and a host doesn't reboot his server just any old time he wants to make a change. But apparently the program based upon your example would have worked if the setting was correct. Is there anything else I have to make sure is set properly with the web host before I continue?
  20. This should do it: $sql_money = "SELECT j_id, amount_invested FROM j_members WHERE j_activated = 1 LIMIT 5"; $result_money = mysqli_query($conn, $sql_money); $split = mysqli_fetch_all($result_money, MYSQLI_ASSOC); Yours wasn't working, by the way, because the query selects j_id and your code refers to $data['id'].
  21. 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
  22. HartleySan

    Chapter 5 Calculator

    Your if condition says, "If the number of hours worked is less than 80 and less than 100, then do something." I think that's your problem. Anything under 100 hours will net you the same result every time.
  23. Speaking in high-level generalities, I think there are two parts to this: Identifying the events that will cause notifications to be created; and Deciding how to display notifications to the users. An example of #1 might be creating a notification for a topic creator every time someone posts something in one of their topics. For example, you might create a notification with the ID of the person who posted in the topic and then the ID of the topic creator, who will get the notification. You can then decide how you want to notify the topic creator. Do you want to send them an email? Do you want to do what Stack Overflow does and have an icon at the top of the site? Do you want both? If you go with the icon approach, then the simple thing to do is to do a check for unread notifications directed at a particular user every time a user loads a page on the site. You could display the number of unread notifications or something, and once they read the notifications, then the number goes down. That's the basic gist. If you want to go into more detail, then we can, but hopefully that's a good start.
  24. 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
  25. The log file helps a lot to debug this. It doesn't look like there's anything obviously amiss, which is to say it looks like all checks are passing. I would next debug this by running your MySQL queries by hand with dummy data to make sure they're all syntactically correct. You can also write more debugging info to the log file, things like "Running the SELECT query." and "No records selected." This should help you know what lines get executed and which don't.
  26. You're running the values through escape_data(), which probably means that the incoming \n (for example) gets turned into \\n which is why nothing else works from there on. And I would just use nl2br() instead of str_replace().
  1. Load more activity
×