Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. Yes - where is the rest of the form? I'm thinking you have a duplicate fieldname in your form code. So - the table has a constraint (or multiples) in that these fields cannot be null.
  2. How about showing us the code that produces that error message? Is it possible a case thing? Your message says 'Custname' but your html says 'custname'
  3. I'd love to help you out but.... Maybe you could work on your English usage too and put together some SENTENCES about your problem and give us a hand in understanding what you are trying to accomplish. I'm sure your problem is very clear in your head. How about giving us a better understanding of what you want so we can follow your code better?
  4. Hmmm... if you feel you don't have the skill to code something and your only recourse is to tell us about it, perhaps you should cease your attempt at programming in php totally. After all the net has answers for everything and you apparently don't want to do the legwork to pick up a new skill. Trust me - being a coder/programmer/IT person is Nothing But Doing The Legwork!
  5. I don't think hidden fields are your answer here. As I suggested - re-think your algorithm. Reconsider why you want an array and not a db. If each entry of h/w represent a "record" of some data, save it as such in your db and when you need the sum of the input for that key value, retrieve all the records for that key with a query and build an output display. Maybe consider two scripts - one for collecting multiple h/v pairs for a specific key value and another for outputting formatted data for a specific key value (or more!). What I've just described s/b an easy "first app" for you. Simple form input, retrieval and storage script. And a simple get key, retrieve data and output results (html table?) script. Remember that your scripts have to "recognize" what to do when they execute. The first will have to distinguish between the "first" run where it merely needs to output the form, and then the "second" run where it retrieves the post data and validates it and does the db update. Same for the second script where it sends a query form asking for a key value on the first execution and a similar retrieve and query and output process on the second run. Once you have done one of these cleanly you will surely begin to see how this all works. I do this by checking for the existence of an expected 'submit' type input tag having a value attribute that I put on my form. If I don't see a submit in my post array that is how I know that it is my first time thru. If I do see a submit button I check the value of it to see which of multiple possible submit buttons I may have placed in my form that was clicked and write code to process each button I expect to see. (Such as a 'Return' button to send the user back to a possible menu screen that got me here in the first place.) If I get a submit value that I don't expect, I assume someone is playing with me and I simply echo out an "invalid" message and exit, killing any attempt to break my appl. Remember that you ALWAYS need to validate your user inputs to ensure that they are what you expect. A very important thing you should learn about is using prepared queries to do your db interactions. This will help ensure that your user inputs are safe when you place them into a query string. IMHO - the PDO interface is the way to go rather than mysqlI. Do Not Use the OLD MySQL interface as you'll see it is clearly marked deprecated in the manual and is no longer even available in the most recent versions of PHP.
  6. I'm guessing that you are using the db value that is returned by the query which would be a type string. Convert that to a type datetime value before using it.
  7. thanks for the heads up MacGyver i wasn't going to click on the links anyway but now i'll be sure not to view the later post either
  8. As we said earlier you cannot assign a header to a var. The header transfers control to another script so what's the point of the assignment to the variable in the current script? I still don't see how you can distinguish where the form comes from and get a different result from this code. Could it have something to do with the JS you are executing upon submit?
  9. My question is not the one you dread, but "why do you believe you need different connections?". I believe that you can simply do your query (union) with just one db connection IF as you said they are all on the same server and all have the same login creds. Plus - how would you ever implement multiple connections in a query? The calls to query functions rely on a single connection, not an array of them. Case solved? As for the query you simply preface tablename with the dbname as in "dbname.tablename"
  10. "No. header() returns no value" Thanks - I thought I knew that. Hoped I was making that point clear to the OP.
  11. IMHO php isn't confusing. The learning process for web development may be the confusion. One has to remember that client-server computing is non-conversational. That means you have to be prepared to start from scratch every time your server-side script is triggered by the client-side user. In this case your original idea of saving things in a PHP variable won't work since every time your script is run it begins from step one again. This kind of thing is definitely not new with PHP nor with computing applications. Heck - it was my biggest learning curve when I first learned CICS on IBM's big iron. You stated that you are new at coding. Might I suggest you step back and read a book and get a feel for what you are embarking upon? Then start with the simple scripts that will teach/familiarize you with writing code, understanding code, knowing what it is like to make mistake after mistake until you get it right and scream "Aha!!" at your minor successes. THEN try some new concepts like html arrays when you get used to how the client and the server connect to each other. You wouldn't start taking apart your carburetor without knowing how it works would you? Bend the wrong piece just a little and you'll never get it running smooth again!
  12. Are you running different scripts? Show us the code - don't tell us what happens. I don't believe this can happen so I want to see this code. Can you assign a header call to a variable? Never saw that before.
  13. What you are not getting is that this script is doing things kinda backwards. You begin by echoing a form out. Then you continue by looking at some potential input. That's not how it works. There is no input on the first run of this script but your script is going to try and do something anyway. What about arrays are you trying to learn? PHP arrays? Or html arrays? You need to write your scripts like this: PHP code and no html //******* HTML code and no php exit Use the php code to check what your current status is. Do you in fact have some input to process yet? If so then do your logical setups to prepare your output form and then do that output and exit. That's it. If you do have input, process the input and figure out what you want to do with it and then produce the results for the user. Maybe you send back the same form, maybe you send something else. Whatever you do DON'T DO THEM ALL AT ONCE. What you currently have is confusing to me and to you I am sure. Personally I use a single function to generate my output html page. The whole document. Inside that html are several/many php vars that contain the data that the early part of the script generated that were passed to this function. My script is very neat looking with all the php logic at the top and all the html at the bottom. Yes - if the logic has to build an html table then the table elements will be wrapped around the php code but no other html code will be in the php section. Same with a select element. Question - when you do the print_r of the $h and $w does the output suggest an array variable was created? If so your following logic s/b giving you errors. Do you have error properly engaged?
  14. The use of the [] naming style for input elements is to produce an array in $_POST to handle multiple inputs of the same "data". In your case your form is only collecting 1 piece of data for height and 1 for weight. You don't need the array syntax here. Maybe you need to think about your design. If you want multiple pairs of inputs you need to design your form for that and then change your php code to get those arrays. Be careful since there is no connection between the height and weight items meaning that a malicious user could enter a height in the first array element and a corresponding weight into the second weight element, thus your arrays would be out of sync. Do you really need to collect multiple pairs at one sitting? You could also use a $_SESSION var to store your inputs but I don't know what you are really trying to do here, so I'll stop.
  15. Entering text on a mobile is no different than a fixed desktop. What makes you think not? YOu have a text input field, no?
  16. Or - perhaps you think that the arrays remain in memory between the two form submits? Remember that once a script ends all of its local variables go away, so whatever you stored during the script's first execution is gone when the next form is submitted.
  17. Hmmm... May I ask why you chose this method? As a relative newbie (since you don't know your JQ well enough) why not do your form strictly thru php? You have your html form. A simple submit button would send all the data to your script and Voila! you can clean the data and send the email from there.
  18. Your memory is better than mine. And you're older too!
  19. A variable is a simple storage holder. You create var $x and you assign it a value. Then you use that variable wherever you need that value. Or you do a calculation and assign the answer to the var $x and use it later on. Simple right? An array is a way of gathering a collection of data items under one Name. Say you want to create an array of your vital statistics, that is - name, age, address, sex. So you create an array and assign it values with either numbers (assigned sequentially as you make additions to it) or "names" (that you assign as you make additions). Here's a sample: $stats = array(); // define the array $stats[] = 'Bob'; $stats[] = 39; $stas[] = '5 Main St.'; $stats[] = 'Male'; A print_r of this array would give you 0 = Bob 1 = 39 2 - 5 Main St. 3 = Male Or an associative array (names): $stats = array(); // define the array $stats['name'] = 'Bob'; $stats['age'] = 39; $stas['addr'] = '5 Main St.'; $stats['gender'] = 'Male'; This would give you: name = Bob age = 39 addr = 5 Main St. gender = Male To reference a specific element of an array (that's what they are called - elements) you reference it by the array name ($stats) and the index you want (the thing in the brackets). Use a number for the sequential array form or a quoted string for an associative array. So to get the address you ask for $stats['addr'] or $stats[2]. Obviously the associative format works better in this case. To look at all of the contents in the whole array you can do this: foreach ($stats as $k=>$v) { echo "$k = $v<br>"; } What this says is "take the array $stats and loop thru it calling each index value $k and each corresponding value $v and output each pair on a line by itself. If this doesn't help then you REALLY need to knuckle down and do some reading. Arrays are a basic structure of EVERY programming language (well, maybe not assembly code) and should be mastered - as much as mastering means to such a simple concept.
  20. One more thing. If you are doing a query with a where clause to find the record that you want, why would you then examine the results to see if the same fields match the input values? By definition they already do!
  21. To be clearer than Ignace was: What does this line do: If you had php error checking turned on you would have seen this by now. (See my signature) And - why do your array print show indices beginning with 1 and not 0? I've never used unpack() but something seems odd here.
  22. The first thing I would change is to separate your html from your php. Keep them apart; use php vars only in the html to pop in dymanic data where you want it. Don't build your html as you gather the data. A key indicator of this is not having to switch in and out of php mode all the time. My scripts use one php tag - a begin at the top of the script. Don't bury functions in the mainline code. They are functions so that you can move that logic away from the main thought process.
  23. I don't you can concat substitute parms. But you can make the values behind those parms work by concatenating the % to the values you assign to those parms.
  24. Do you mean query them together? Or do separate queries on each?
×
×
  • 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.