-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
How to handle different form submit actions on the same page?
ginerjm replied to greenace92's topic in PHP Coding Help
Actually I don't know how my logic can fail since I ALWAYS name the buttons the same and then use the same logic to handle them, as I showed. And as for the check for request_method - if my search for a $_POST element fails then my code fails, as it should if it doesn't find a defined button. -
While what you say makes sense, it is a good constraint for this appl since a player can only play one match a night.
-
Interesting... minor syntax changes and it works. Funny I've used the methods employed here bedore but this time there must be something unique about it. Here's my now-working code: $q = "select date_format(a.Match_date,'%m/%d/%y') as Match_date, a.Team_no, a.Player1, a.Player2, b.Last_Name as p1ln, b.First_name as p1fn, c.Last_name as p2ln, c.First_name as p2fn, s1.Player_no as scored1, s2.Player_no as scored2 from dart_matches as a join voorhees_data.MMS_Members as b on a.Player1 = b.Roster_no join voorhees_data.MMS_Members as c on a.Player2 = c.Roster_no left outer join dart_match_scores as s1 on s1.Player_no = a.Player1 and s1.Match_date = $qdate left outer join dart_match_scores as s2 on s2.Player_no = a.Player2 and s2.Match_date = $qdate where a.Match_date = $qdate order by a.Team_no"; Thank you very much!
-
Heres the one that is giving me the problem: Array ( [Field] => Match_date [Type] => date [Null] => NO [Key] => PRI [Default] => [Extra] => ) Array ( [Field] => Team_no [Type] => int(11) [Null] => NO [Key] => PRI [Default] => [Extra] => ) Array ( [Field] => Player1 [Type] => varchar(3) [Null] => NO [Key] => [Default] => [Extra] => ) Array ( [Field] => Player2 [Type] => varchar(3) [Null] => NO [Key] => [Default] => [Extra] => )
-
Not my first time doing this but I'm missing something today. Gonna really hate it when you point out my problem here. My query: $q = "select date_format(a.Match_date,'%m/%d/%y') as Match_date, a.Team_no, a.Player1, a.Player2, b.Last_Name as p1ln, b.First_name as p1fn, c.Last_name as p2ln, c.First_name as p2fn from dart_matches a, voorhees_data.MMS_Members as b, voorhees_data.MMS_Members as c left outer join (select Player_no as scored1 from dart_match_scores where Match_date = $qdate) as s on a.Player1 = scored1 left outer join (select Player_no as scored2 from dart_match_scores where Match_date = $qdate) as t on a.Player2 = scored2 where a.Player1 = b.Roster_no and a.Player2 = c.Roster_no and a.Match_date = $qdate order by a.Team_no"; The error I keep getting is: Column not found: 1054 Unknown column 'a.Player1' in 'on clause' The thing is my table structure clearly shows the existence of Player1 in my table and have prefixed every occurrence of it in the query, there are no duplicates and yet this is where it keeps stopping no matter what I do. Thanks in advance!
-
How to handle different form submit actions on the same page?
ginerjm replied to greenace92's topic in PHP Coding Help
Just my $.02 here. As a general practice I name all of my submit buttons as "name='btn'". All my scripts then do this: if (!isset($_POST['btn']) { handle the first time into your script here, send your output html and exit. } $btn = $_POST['btn']; if ($btn == 'Return') { handle my return (to previous caller) button header() exit() } if ($btn == 'Do This') { } if ($btn == 'Do That') { } // handle unexpected input. echo "Unknown button submitted $btn"; exit(); Obviously, each button has a different label on it and that is how my script knows what to do. -
Read a book. Check out codeacademy online. There's a lot to learn to become a coder, let alone a good one. Make it easier on yourself with some basic walk-before-you-run efforts.
-
Ok - solved my own problem. Instead of my html calling a routine to validate the input with an onchange call and then handling an Enter key as a Tab with an onkeypress event I consolidate my activities. With an onkeydown I call my edit routine. In there I check for a tab or enter key. If it's not one I simply ignore it and return. IF the key is an Enter or Tab I perform my editing and if that fails I manage to do either a preventDefault or stopPropagaion and return false. If it passes the tests, I call my routine to handle an Enter as a Tab and then return true. So now - user can do d/e and hit enter or tab when done. The screen will edit my entry and either keep me on the field or move to the next tabstopped field. Just what I need.
-
I found out that onblur can be (is really!) a PIA. Just leaving the page causes it to occur and trying to leave the field causes many considerations. So - any ideas on why my current code won't work? It's a simple d/e screen as I may have said - type in a number and hit enter, and repeat. I just want to edit each number at the time of entry rather than have to go back and look at them all if there is an error.
-
Apparently my time ran out before I could edit the first post. Please look at this instead. My input elelments: <input type='text' class='sz3' name='pfld11' id='pfld11' value='$pfld11' tabindex=3 onchange='return getName(event,this)' onkeypress="return moveToNextTabOnEnter(this, event)"> And my JS function: function getName(e,elem) { var id = elem.id; var key = elem.value; var name_fld = 'name' + id.substr(-2,2); if (key == '') { alert("You must provide a Roster #"); e.preventDefault(); elem.focus(); return false; } if (!membs.hasOwnProperty(key)) { alert("Invalid roster #"); e.preventDefault(); elem.focus(); elem.select(); return false; } document.getElementById(name_fld).value = membs[key]; return true; } I think I'm getting the event passed to the function properly now since I no longer get messages in the debugger. Still doesn't prevent the tab from happening though.
-
ok - this borders on a previously posted question but I'll try to be more specific with this one. I have a d/e form that collects some entries that must be valid. They get checked against an array of valid values and if wrong I must make the user repeat the entry. So - I add an 'onchange' call to each input element tag to call my js edit function. In it I do the check and if it fails I want to place the focuse back on the element and select it and popup an alert box with the problem and then let the user re-enter his value. The problem is I can't keep the focus where I want because it just naturally wants to move to the next tabstop. Here's my code: <input type='text' class='sz3' name='pfld12' id='pfld12' value='$pfld12' tabindex=4 onchange='getName(this)'> And here is the js code: function getName(elem) { var id = elem.id; var key = elem.value; var name_fld = 'name' + id.substr(-2,2); if (key == '') { alert("You must provide a Roster #"); elem.focus(); elem.preventDefault(); return false; } if (!membs.hasOwnProperty(key)) { alert("Invalid roster #"); elem.preventDefault(); elem.focus(); elem.select(); return false; } document.getElementById(name_fld).value = membs[key]; return true; } </script> The js works fine - it's just the end result when the entry is invalid that is my problem. So - how do I move the focus back to the calling element and avoid the natural tendency to move forward to the next field?
-
Sounds like you've given up, because I know I wasn't able to give you anything other than some advice. ok - here is one problem: ['confessId']."" You end your string with two double quotes. Plus if confessed is not numeric you need single quotes around it. Turning on php error checking would have told you that. Again you do this: SELECT 'X' FROM comments... Why do you want to collect a set of rows with nothing but an X in them?
-
Do you have error checking turned on? (my signature) If you can't tell us what is or isn't happening how do you think we can help you - besides telling you that the current process is just plain bad practice?
-
Not a good solution to do a query inside a loop, let alone two of them! Why aren't you writing an all-inclusive query to avoid all that? That said - please define 'broke'. Programmers need precise information to help solve problems.
-
Perhaps instead of suppressing the error you trap for a False result and either then ignore it or display a short message to the user? if (fopen($filename) === False) { $err_message = "Could not open file: $filename"; // include this var in your final output // decide here whether to continue on or not } // at this point you have successfully opened it. Just my $.02.
-
turn on php error checking.
-
Just to throw another idea out there since you had a problem with the bindparam calls. Use the execute() method with an array of your parms in place of all those individual bind calls. Much easier to implement IMHO.
-
mysqli conversion on fetch_assoc and real_escape_string
ginerjm replied to acctman's topic in PHP Coding Help
Requinex - Yes I noticed the mismatch in the OPs use of function sets. I thought it was more important to get him/her to change the outdated functions and improve his coding practices instead of having him/her 'correct' one statement to old, outdated code. -
I'm getting close to a solution. Involves initializing my empty php data var when passing them to the script that json.parses them.
-
mysqli conversion on fetch_assoc and real_escape_string
ginerjm replied to acctman's topic in PHP Coding Help
1 - you didn't show us where you actually called your connection function. 2 - your function should do some testing of the results of its actions (as you should in ALL code) to ensure that the connection was made. Perhaps it wasn't made and that is your problem which you would have known if you had done simple basic error checking. One should always take advantage of the return results, uaually Boolean, to ensure that unexpected things haven't interfered with your PHP code's execution. Things like db connections, query calls, external file opens/closes and other things that rely on the rest of the world functioning normally. 3 - STOP using the MySQL_* functions. Look them up in the manual. Note the red print (is it still red?) telling you that the interface is deprecated - that means outlawed - and is already removed from the latest version of PHP. -
What again is wrong with my use of innerText? It gets me what I want. Again - all of my code seems to work just fine on any existing record data. It's only on new data that the screen breaks down. There must be some trick to properly initializing the empty array created in PHP and then being encoded to go to the javascript. Can I not simply define the empty array and pass it thru the same code that the populated one goes thru?
-
I don't use jquery.
-
What is console.log? Is that js command? And what does it do? the add occurs one at a time.. The appl screen collects header rec data and then the individual names that need to be linked to that header data. I build the list of the details as the user does his d/e and then the submit passes the header data and all of the json-encoded names to PHP where the data is all posted into two tables. I have no html in the data.I'm building an object/array or the member names and their keys.
-
Any header call s/b followed by an exit() command. When one has the need to use the header location command he is saying he's done with the current script.
-
With much help from Jacques and the forum I managed to get my php data into js with json and my appl now manages to do adds/deletes and the passing of results back to my php script to be updated into MySQL. All works great for existing data. My problem now is with the json part for entirely new records. When my php passes an empty array to json and to js and creates the web page, the very first add to the json object creates an object filled with null entries followed by the just-added piece of data. Alert messages tell me this: before the add, the item is (empty) and its type is object; after the add, the item becomes: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,new, name and its type is still object. As you can see I am getting a series of null elements in my object but I dont' know from where they come. This doesn't happen (as I said) when working with existing data, only with new data records that have no json data to start with. My process is simply: atts = JSON.parse(document.getElementById('json_atts').innerText); and at startup an alert says it is empty and its type is object. To add: (before this add, atts is empty but of type object) atts[key] = membs[key]["name"]; after the above line atts is: ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Giner, Jim (a whole bunch of commas) What is causing this strange behavior? I am completely baffled by this because I'm a complete noob/incompetent at this json stuff. What I don't get is why this works for existing data that adds or deletes to the json-encoded data but the same logic won't work when the beginning data is empty.