Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'post'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Found 9 results

  1. In Chapter 11 in the sending email script called email.php, the $_POST['name'] and $_POST['comments'] in the $body variable are wrapped in curly braces. Why are there curly braces around them. See the code below. if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments'])){ $body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}"; $body = wordwrap($body, 70); } }
  2. I have a form like the one below which is posted to processForm.php, and the user can dynamically add more with jquery. <input type="text" name="subject[ ]" /> <input type="text" name="grade[ ]" /> <input type="text" name="year[ ]" /> <input type="text" name="subject[ ]" /> <input type="text" name="grade[ ]" /> <input type="text" name="year[ ]" /> <input type="text" name="subject[ ]" /> <input type="text" name="grade[ ]" /> <input type="text" name="year[ ]" /> Please How can i access those arrays from subject[], grade[] and year[] inputs by the user?
  3. I probably have some kind of visual/spacial related learning disability. I know that a form sends data to the server where php processes it and outputs it to the browser. Words alone don't always work for me. I have to draw things as if I were trying to explain it to someone else. Some times that helps me to see that my logic simply doesn't compute. Thought I was good to go with arrays... $var = array('dog', 'cat', '2', 'blue'); $var now contains all the values in the array. But, in the book, the syntax (using post) is: $title = $_POST['title']; $name= $_POST['name']; $email= $_POST['email']; To this newb it appears that the array concept has been abandoned for a multi-variable "device". I realize it's my inability to grasp it. (Tried to post the drawing but got "that extension not allowed" with png, gif, jpg. Finally gave up and put in a link instead) My drawing shows what I think happens. (I like to think I--at least-- have that much right.) But it still seems clunky. Would like to get a grip on this and share with other seniors (dob: 12-7-45). http://chattanoogacentral1964.com/drawing.php
  4. I'm working my way through Chapter 13 and I'm unable to get my edit_quote.php page to work. The error message I'm getting is: I understand that the reason for this is that the script isn't getting a valid ID. I'm just not sure why. Here's my code. I've reviewed it line-by-line a few times, but I'm not seeing the problem: <?php define('TITLE', 'Edit a Quote'); include('templates/header.html'); print '<h2>Edit a Quotation</h2>'; //Restrict access to adminsitrators only. if (!is_administrator()) { print '<h2>Acess Denied!</h2> <p class="error">You do not have permission to access this page.</p>'; include('templates/footer.html'); exit(); } //Need the database connection. include('includes/mysql_connect.php'); if (isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0)) { // Display the entry in a form. //Define the query. $query = "SELECT quote, source, favorite FROM quotes WHERE quote_id={$_GET['id']}"; if ($r = mysql_query($query, $dbc)) { //Run the query. $row = mysql_fetch_array($r); //retrieve the information. //Make the form. print '<form action="edit_quote.php" method="post"> <p><label>Quote <textarea name="quote" rows="5" cols="30">' .htmlentities($row['quote']). '</textarea></label></p> <p><label>Source <input type="text" name="source" value="'.htmlentities($row['source']). '"/></label></p> <p><label>Is this a favorite? <input type="checkbox" name="favorite" value="yes"'; //Chec the box if it is a favorite. if ($row['favorite'] == 1) { print ' checked ="checked"'; } //Complete the form. print ' /></label></p> <input type="hidden" name="id" value="' .$_GET['id']. '" /> <p><input type="submit" name="submit" value="Update This Quote!" /></p> </form>'; } else { //Couldn't get the infomration. print '<p class="error">Could not retrieve the quotation because:<br/>' .mysql_error($dbc). '.</p> <p>The query being run was: ' .$query. '</p>'; } }elseif (isset($_POST['id']) && is_numeric($_POST['id']) && ($_POST['id'] > 0)) { //Handle the form. //Validate and secure the form data. $problem = FALSE; if (!empty($_POST['quote']) && !empty($_POST['source']) ) { //Prepare the values for storing. $quote = mysql_real_escape_string(trim(strip_tags($_POST['quote'])), $dbc); $source = mysql_real_escape_string(trim(strip_tags($_POST['source'])), $dbc); //Create the "favorite" value. if (isset($_POST['favorite'])) { $favorite = 1; } else { $favorite = 0; } } else { print '<p class="error">Please submit both a quotation and source.</p>'; $problem = TRUE; } if (!$problem) { //Define the query. $query = "UPDATE quotes SET quote='$quote', source='$source', favorite=$favorite WHERE quote_id={$_POST['id']}"; if ($r = mysql_query($query, $dbc)) { print '<p>The quotation has been updated.</p>'; } else { print '<p class="error">Could not update the quotation because:<br/>' .mysql_error($dbc) . '.</p><p>The query being run was" ' .$query. '</p>'; } }// No problem! } else { // No ID set. print '<p class="error">This page has been accessed in error.</p>'; } // End of main IF. mysql_close($dbc); //Close the connection. include('templates/footer.html'); //Include the footer. ?> Thanks!
  5. Hi, I have a script that works OK but I'm not sure if it's by design or by accident. On pages 91 through 94, Larry advises on how to use PHP redux, a technique that I use often. Here's my scenario: I have a PHP script, let's call it script one, that calls PHP script 2 and passes a key value to it. I test for a key value as the first thing in script 2 via 'if (isset($GET['key']))' and retrieve its value. This works fine. Then script 2 uses that key value to populate a form with values from a database select. The user is able to change any of the values in the form. Script 2 then calls itself via PHP redux. Now this is the part that I don't quite understand. The form is method=POST and that same key value is included in the form via an input type=hidden, a name of 'key', and the value via a PHP echo. But the test for isset($GET['key']) still works and retrieves the correct value for key. But the form is POST? On the URL for the redux-called script two I can see the '?key=key-value suffix. Can someone please help me understand this? Thank you in anticipation.
  6. Have a situation where - when submitting form data to a php script - the ajax script stalls at: ajax.send(data); When the script stalls, it throws no error messages and returns no results. It just stalls. The php script runs all of its scripty things perfectly sans ajax, so I know the php and mysql is solid. It's just when it comes to incorporating the ajax that there is any issue. But wait - there's more. When the script is under the influence of ajax, and stalls, the Firebug console displays this line of text in red (red obviously indicating some kind of error, even though there's no error message given): The reference to (line 60) is the very line where the aforementioned ajax.send call resides. Now, here's where things get really screwy: If I go into Firebug, right-click on that red console line (shown above) and select 'resend' - everything works perfectly. What the . . .heck? Is there something obvious happening here that everyone (besides me) knows, or should I post some of the code for further scrutiny? ~ David
  7. Hi Larry, Great fan of you books! I've recently gone over Chapter 11 and I had a question regarding passing data from JSON to PHP using the code provided in the book for test.js (434-436). I've modified the script to use JSON and that works beautifully. I'd like to know if there is a clean JS solution to pass data to PHP without relying on jQuery.ajax({ data })? I've looked everywhere for a solution but the solution seems easily resolved with jQuery, but I'd like to avoid that if possible. Here is the code I've used as dictated in the book: 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) ) { var data = JSON.parse(ajax.responseText); var file = ''; file += 'Original: ' + data['org'].file + '<br>'; file += 'Processed: ' + data['pre'].file + '<br>'; document.getElementById('output').innerHTML = file; } else { document.getElementById('output').innerHTML = 'Error: ' + ajax.statusText; } } }; document.getElementById('btn').onclick = function() { ajax.open('POST', 'resources/test.json', true); ajax.setRequestHeader('Content-Type', 'application/json'); ajax.send(null); }; }; I would like to be able to echo out the data['org'].file and data['pre'].file in PHP after the request is made. Any guidance or suggesting would be appreciated.
  8. Version 0.5 Page 126 Quoting from the book: "For example, when updating a post record, the URL is something like http://www.example.com/index.php/post/update/id/23." Where is the file called "post"? I have searched the entire project, using Windows Explorer, and I cannot find it. Also, I've never heard of a "post record". What is that? Thanks.
  9. Hi everyone I am working through the book again and am really having trouble getting my head round the shopping calculator (shopping.html, page 103), so would be grateful if you would review my comments to say if I have understood it correctly:....... *****MY COMMENTS ARE LIKE THIS************* -------------------------------------------------------------------------------------------------------------------------------------- *****THIS IS LARRY'S HTML - 'shopping.html'********* <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Shopping Calculator</title> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link rel="stylesheet" href="css/styles.css"> </head> <body> <!-- shopping.html --> *****THE COMMAND '<form action=' WILL SEND AN ARRAY, ON SUBMITTING OF THE FORM, OF THE 5 VARIABLES, EACH WITH ITS VARIABLE NAME (E.G. "quantity, 4") BY METHOD "POST" WHICH WILL BE "INTERCEPTED" BY THE JS SCRIPT********** <form action="" method="post" id="theForm"> <fieldset> <p>Use this form to calculate the order total.</p> <div><label for="quantity">Quantity</label><input type="number" name="quantity" id="quantity" value="1" min="1" required></div> <div><label for="price">Price Per Unit</label><input type="text" name="price" id="price" value="1.00" required></div> <div><label for="tax">Tax Rate (%)</label><input type="text" name="tax" id="tax" value="0.0" required></div> <div><label for="discount">Discount</label><input type="text" name="discount" id="discount" value="0.00" required></div> <div><label for="total">Total</label><input type="text" name="total" id="total" value="0.00"></div> <div><input type="submit" value="Calculate" id="submit"></div> </fieldset> </form> ****NOW CALL THE JAVASCRIPT******** <script src="js/shopping1.js"></script> </body> </html> ******THIS IS NOT THE JS USED BY THE HTML BUT IS ESSENTALLY IDENTICAL EXCEPT WITH MORE OF LARRY'S COMMENTS.************* // Script 4.2 - shopping.js // This script calculates an order total. // Function called when the form is submitted. // Function performs the calculation and returns false. ******THIS STARTS THE FUNCTION THAT WILL BE CALLED AT THE END BY THE VARIABLE 'theForm' (MORE ABOUT THAT LATER).********** function calculate() { 'use strict'; // For storing the order total: ******'total' IS A SIMPLE VARIABLE TO STORE THE DECIMAL NUMBER THAT WILL RESULT FROM THE CALCULATION*********** var total; ******MOVE THE VARIABLES FROM "POST" TO JS*************** // Get references to the form values: var quantity = document.getElementById('quantity').value; var price = document.getElementById('price').value; var tax = document.getElementById('tax').value; var discount = document.getElementById('discount').value; // Add validation here later! // Calculate the initial total: total = quantity * price; // Make the tax rate easier to use: tax /= 100; tax++; // Factor in the tax: total *= tax; // Factor in the discount: total -= discount; // Display the total: document.getElementById('total').value = total; // Return false to prevent submission: return false; } // End of calculate() function. *****NOW WRITE THE LISTENER********* // Function called when the window has been loaded. // Function needs to add an event listener to the form. function init() { 'use strict'; // Add an event listener to the form: *****AND THIS IS WHERE I HAVE A PROBLEM........WHY ARE WE CALLING ALL OF THE DATA AGAIN BY WAY OF 'theForm'? IS 'document.getElementById('theForm')' CALLING THE WHOLE POST ARRAY AND WHY? var theForm = document.getElementById('theForm'); *****CALL THE "calculate" FUNCTION***** theForm.onsubmit = calculate; } // End of init() function. *****THIS CALLS THE "init" FUNCTION WHEN THE WINDOW LOADS****** // Assign an event listener to the window's load event: window.onload = init; --------------------------------------------------------------------------------------------------- The only other possibility that I can think of is that "var theForm = document.getElementById('theForm');" calls an array from POST that includes all of the variables stated above, and then passes them to the "calculate" function as required. To put the question another way, is the variable e.g. "quantity" - the actual number - received directly from POST or secondarily from the array "theForm"? I imagine the variable "the.Form" to look like this: quantity,4 price,45.67 tax,20 discount,10.00 total,0.00 Any comments and advice would be greatly appreciated. Regards Max
  • Create New...