Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by phppup

  1. Note: My hosting service has said the server is fine and the problem is within my code. Does anyone see an issue or have any suggestions?
  2. I'm lost. Please be more specific with detailed instructions, if you would.
  3. I added this immedately after my <? but got nothing.
  4. My form is not posting data to table. I removed all validation to simplification purposes, yet onSubmit only provides a blank page. I have used a script and verified connectivity to the db, and feel as if there is something wrong with my INSERT statement. Here is my code: my_form.php <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="POST" action="insert_file.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Lastname</td> <td>:</td> <td><input name="lastname" type="text" id="lastname"></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </td> </tr> </table> insert_file.php <?php $host="localhost"; // Host name $username="provided"; // Mysql username $password="provided"; // Mysql password $db_name="provided"; // Database name $tbl_name="provided"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $name=$_POST['name']; $lastname=$_POST['lastname']; $email=$_POST['email']; // Insert data into mysql $sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Do you see something that I've missed??
  5. @Requinix:"Most effective way" to do what, exactly? To work with TIME in general. It seems JS requires manipulations from milliseconds in order to adopt user friendly information. PHP/MySQL appear to be able to accommodate 'real dates', so I avoid an added headache. I'd this a fair assessment? "I shouldn't have to explain why" Perhaps not. But would it hurt if you did? Obviously I'm on the right track because I made the comparison. Èqually obvious is my lack of clarity on the subject because I asked the question. I created my screen name to indicate that I was new and (while eager to grow) still bumping into walls and making (what the more experienced would consider) silly mistakes. The screen name had nothing to do with my affection of canines. "Informative and sensative responses will educate and empower the website capabilities while reducing recycled post volume." Me.
  6. I am planning to use a JQuery datepicker as an easy user interface on a form. This will identify a "start date" that the user will select for his 5 day work shift. The data will go into a table and other calculations will use this start date going forward. What is the most effective way to handle and manipulate this data for this situation? Is there a benefit or best practice? Is it better to format date information using JavaScript on the client side, or with PHP? Should I insert a date as mm-dd-yyyy or yyyy-mm-dd, or something else. Does it even matter? Any helpful hints and opinions to point me in the right direction would be great.
  7. Would you believe that I was unsure of exactly how to make the PDO connection and that the reason I changed to a 'more comfortable' connection was because I could not get the PDO to work? Or do you think that I changed it just to elicit more problems as a means to continue this fascinating dialogue??
  8. OK. Of course, I wouldn't have changed it if I knew where to place the information for the PDO connection. So, let me ask, "where do I put the information so that the PDO-devoted code will connect? And, assuming it does eventually connect, I will be back to my initial question: How do I update the selected record?????
  9. Here's the code straight off the server (sorry, don't know how to encapsulate it). The code is not populating data, and offers no method for 'attaching" the the selected record for UPDATE (which was my initially issue) after dynamically searching the table. <?php //include 'db_inc.php'; $db = mysqli_connect("localhost", "MY_INFO", "MY_INFO", "MY_INFO"); //$db = pdoConnect>>>> REMOVED // AJAX PROCESSING BIT if (isset($_GET['custname']) && trim($_GET['custname']) != '') { $stmt = $db->prepare("SELECT customer_id , fname , lname , phone FROM customer WHERE lname LIKE ? ORDER BY lname, fname, phone"); $stmt->execute( [ $_GET['custname'] . '%' ] ); $opts = ''; foreach ($stmt as $r) { $opts .= "<option value='{$r['customer_id']}'>{$r['fname']} {$r['lname']}, {$r['phone']}</option>\n"; } exit($opts); // return the options as the AJAX response } // report the selected customer if (isset($_POST['customer'])) { echo "You selected customer #{$_POST['customer']}<br><hr>"; } ?> <html> <head> <meta name="generator" content="PhpED 18.0 (Build 18044, 64bit)"> <title>Sample AJAX</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready( function() { $("#custname").keyup( function() { $.get( "sample_ajax.php", { "custname" : $(this).val() }, function(resp) { $("#customer").html(resp); }, "TEXT" ) }) $("#customer").change( function() { $("#fm1").submit(); }) }) </script> </head> <body> <form id='fm1' action="" method='post'> Enter last name<input type="text" name="custname" id="custname" size="20"> <br><br> <select name='customer' id='customer' size=10 > <!-- ajax response text goes here --> </select> <br><br> </form> </body> </html>
  10. For code that does not work, the attempt is appreciated, but not as much as a reply that resolves my issue. Your code did not work. Nor did it address the problem ( (as no update option was included. AJAX seems like a nice way to view data in my table. But I need a way to utilize it. Is there a way to Cchoose aspecified record and UPDATE it?
  11. After several attempts of adjusting this code and creating database tables, it appears not to work and has failed. Perhaps I should rephrase: hope do I use the selected item from an AJAX generated search so that the specific record can be updated in its table? Any helpful info, links, examples would be appreciated.
  12. This looks similar to what I've got: another AJAX developed menu. So, back to my question: after I make a selection, how does I carry the values and UPDATE the record? EG: I select John Smith with tele 5554321 and need to change his girlfriend's name from Mary to Wanda. I need to be able to UPDATE the correct corresponding record.
  13. Please re-read my initial entry. The dropdown-style is created with AJAX pulling data from the columns in distint rows (whether 'name' and 'phone' or 'state' and 'abbrev'). I created the following as a way to see it. function Delta(){ var x = document.getElementById("typ").value; document.write("You selected <b>" + x + "</b> as your choice."); In what manner would I use you suggestion as an alternative??
  14. The AJAX that I've got is end result of several suggestions and resources. The full story and it's reality for an end result may untangle the confusion. I have a form for customer information that inputs data into a table. That works fine. This customer information corresponds to other related data (ie. last sale, amount, etc.) through a non-disclosed index number. Since there is a likelihood that a 'first name' and 'lastname' may be duplicated (more than one John Smith), it is imperative that the correct record be updated. Enter AJAX, which enables user to enter keystrokes that narrow the field of John Smith's dynamically. The Smithers, Smithsons, and Smithers have been visually eliminated from the dropdown-style display. Now, there are three John Smith choices. In addition to 'firstname' and 'lastname' is 'phone'. This can be used to validate that from the choices, the correct John Smith is selected (with the associated [hidden] index. Great up to here. The table is populated, the data is dynamically visible. John Smith with'phone' 5551224 is selected. And then, NOTHING HAPPENS. I need to carry the 'phone' or the index to the next phase in order to update his girlfriend's name or add today's sale data. This is where I've stalled.
  15. Ummm, no. I posted originally in PHP and the post got moved to this forum. I would prefer a PHP solution (but will try this for educational purposes). Still would like the PHP method. Thanks for the help.
  16. Even if I stagger the execution intervals of job 1 and 2, there would be no guarantee during a presentation that there is no delay, at which point cron2 would run before cron1. Unless my thinking is wrong, I would like to run cron1 and incorporate something similar to a js script saying "wait 5 minutes and execute cron2." Can this be done?
  17. In its current form, the script does nothing more than dynamically display information contained in the table. I want to be able to now utilize it. Knowing that California (as 'state') exists does me no good if I cannot select it to update 'abbrev'. This is only a template right now. Simplified plans would replace 'state' with 'customer' and 'abbrev' with 'satisfaction'. In that case, customer Smith would be selected from Ajax. His satisfaction with our service is a 10. Today, he was disappointed and the 10 needs to be UPDATED to a 3. Currently, I am unable to satisfy that criteria t through a form because I cannot 'grab' there variable information and retain it for page 3.
  18. The table (which has not been coded bc I realized this issue) would simply likely refer back to an identifying retirement 'id' with rows 'sale'(a positive number), 'credit' (a negative), and 'current_balance' (for the running total). Obviously, I could always SUM both columns and do basic math tho calculate a total. My problem is how to get to the last balance (in the prior row corresponding to the particular 'id' and running a continuously updated cycle. In Excel it would be E2+C3-D3 to equal E3. My problem is getting to E2 (the last/previous sale record for this customer).
  19. After trolling the internet, I have managed to piece together enough information to accomplish the creation of a working Ajax script which dynamically shows the contents of a table column when a user types inside a text input field. So, the data from table STATES provides the 'name' field California and the 'abbrev' field CA. This seems to be accomplished when the first php files connects to the second php file through: $.get("backend.php", {term: inputVal}).done(function(data){ Now I want to put the selected information to use. How can I attach/connect 'name' or 'abbrev' so that these variables are selected in a third file update.php so that CA can be altered to "Cali" The input field displaying this info is name= 'typ' and I've managed to create a JavaScript: function Delta(){ var x = document.getElementById("typ").value; document.write("You selected <b>" + x + "</b> as your choice."); But this displays the information as a string. It seems like the long way around to use Java Script to disassemble the string and isolate each variable. And then, of course, I need to pass it to update.php Please help.
  20. How can I calculate a running balance using PHP? I have a table that will record both sales and credits and would like to display a cumulative balance. It seems redundant to have to revisit every individual transaction and recalculate the current balance each time it is required. How can I set up an additional column named "balance" and use it as a reference point against the newest entry for the specific customer? What is the best method of achieving a checkbook-style method?
  21. How can I calculate a running balance using PHP? I have a table that will record both sales and credits and would like to display a cumulative balance. It seems redundant to have to revisit every individual transaction and recalculate the current balance each time it is required. How can I set up an additional column named "balance" and use it as a reference point against the newest entry for the specific customer? What is the best method of achieving a checkbook-style method?
  22. I have created a Cron job that will send an email to new subscribers when they register. A second email will be sent a week later. For demonstration purposes, waiting more than a few minutes for the second email is not practical. Is there a way within PHP to set a timeout function, so that email number two can be initiated shortly after email number one?
  23. I am creating a database with the personal information of customers at a small business. Many of the customers are local residents, while some are business owners. For those customers with businesses, the company name and a corporate designation is desired. For purposes of database normalization, is it really necessary to create a separate table for these two pieces of information. What is the real downside of having two more rows in a single table? Helpful information appreciated.
  24. I'm starting of with a simple form to gather information and then store it in a database. While researching methods and techniques I discovered this: $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $email = mysql_real_escape_string($_POST['email']); Is it necessary to run mysql_real_escape_string for every item? Is there a more effective/efficient manner to handle this? Is there a better approach from a security standpoint? Please educate me.
  25. Thanks a ton. I have already begun doing some homework regarding AJAX and quickly learned that it sometimes (as I'm my case, naturally.. LOL) fails when used from smartphones. I will test your script and the others I've uncovered in tutorials tomorrow.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.