Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
"Which" custom error is being presented? I assume the custom error should prevent the record from being inserted. So, I further assume that your problem is that you believe the custom error is being triggered erroneously. But, that is a lot of assuming on my part. How about we change this around and you actually tell us the problem instead of us playing 20 questions? I know that when you are working on a problem, all these things seem "obvious" to you. But, when you need help, you need to step back and determine the relevant information to provide. A good rule of thumb would be to follow a normal bug report: 1. What are the steps to reproduce the issue 2. What is the expected result 3. What is the actual result
-
What "problem" are you having - exactly. What IS getting saved in the database? Or, are you getting errors? If so, what are they? Here are a few things you should verify: 1. Do a View Source on the form page and inspect the Select Options are properly formatted and that their values are the IDs that you expect. 2. Run this in the code the handles the form submission to verify the complete and correct data is being submitted echo "<pre>".print_r($_POST, 1)."</pre>"; 3. echo the query tot he page to ensure it is correct. Also, you can copy/paste the derived query into your database management console (e.g. PHPMyAdmin) to verify it is valid and see if there are any errors. Pro tip: Create and test your queries in a management console first (with hard coded data). Once you have them working as you want - then put them in your code replacing with the dynamic values. NOTE 1: Your code is wide open to SQL injection. You should be using prepared statements. NOTE 2: Who are you to say what characters may be in a person's name? What about a person with a hyphentated name "Julie Brown-Smith" or what about someone with diacritic characters in their name: "Robert Muñoz"
-
Any ideas why code is inserting just one character of each value?
Psycho replied to sonnieboy's topic in PHP Coding Help
Well, that's my fault. I use PDO and would just use the $sname in the execute statements instead of defining the values as defined variables. In my haste I threw in the list() function not thinking it only worked for numerically indexed arrays. -
Any ideas why code is inserting just one character of each value?
Psycho replied to sonnieboy's topic in PHP Coding Help
Change your form field names to this structure name="employee[<?=$id?>][employeename]" name="employee[<?=$id?>][ttitle]" name="employee[<?=$id?>][email]" . . . etc. Then on your form processing code you can do this $sql = "INSERT INTO table_name (employeename1, ttitle, email) VALUES(?, ?, ?)"; $sth = mysqli_prepare($conn,$sql mysqli_stmt_bind_param($sth, 'sssssss', $employeename, $ttitle, $email); //Iterate through each RECORD in the post data foreach($_POST['employee'] as $employee) { //Extract array fields into variables for prepared statement list($employeename, $ttitle, $email) = $employee; //Execute the query mysqli_stmt_execute($sth) } Note, I've left off a lot of error handling on this for brevity, but you should be able to see the concept., -
Pretty much what I was going to say. You just need an array of the database names along with a single connection. Then you can dynamically build the UNION queries something like this: //Create a query "mask" with placeholder for DB name $queryMask = "SELECT field1, field2, feild3 FROM [DB_NAME].tablename"; //Iterate over each DB creating the clause //for each DB replacing the mask $unionClauses = array(); foreach($databases as $db_name) { $unionClauses[] = str_replace('[DB_NAME]', $db_name); } //Cobine all the clauses with a UNION $query = implode("\nUNION\n", $unionClauses); //Using line break '\n' to make the query readable if you need to echo it out
-
The issue, is that you post a question and then a few minutes later you post that you've resolved it. That's great. You will learn much more by solving your problem yourself than someone just telling you what the problem is. But, there are two reasons why seeing such behavior will make me not want to post a response: 1) It would seem that the OP did not take the time to at least attempt to solve their problem before posting. Providing help to such people would only encourage them to not try to solve their own problems. 2) If I take the time to research the issue and post a response, the OP may already find the solution before I get a chance to reply. Nobody gets paid to provide help here. We do this because we like helping people. So, the fact that someone was not really "stuck" and was just posting a "drive-by" question while they complete their due diligence makes me feel like they do not value my time. I'm happy to help, really I am. But, if I find that my time is being wasted, I will be less apt to reply. You are free to post however you like (as long as it meets the forum rules), I am just providing some constructive criticism that I believe will help you get more and better responses.
-
You need to slow down. All of these drive-by posts are going to make people (i.e. me) decide not to help. If you get an error - read it. What do you think the error means? Then look at the code in question and determine what may be going on. An "array to string conversion" is pretty self explanatory. You are referencing a variable that is an array and you are performing some function on it that is intended for a string type value. Note: Many times when you get a parsing error, the error is actually before the line on which the error actually exists. PHP will report the line oin which it reached a place where it cannot understand what to do. For example, if you forget to close a string variable with double quotes, the PHP parser will think the lines of code following that line is part of the string you are defining. It isn't until it sees a closing quote mark that it will identify the error. FYI echo "<input type='hidden' name='employeename[]' value='".$sourcename1."' />"; echo "<input type='hidden' name='ttitle[]' value='".$sourceaddress1."' />"; echo "<input type='hidden' name='sourcename1[]' value='".$income1."' />"; When defining string with double quotes, there is no need to exit the quotes to append a variable. You can do this echo "<input type='hidden' name='employeename[]' value='{$sourcename1}' />"; echo "<input type='hidden' name='ttitle[]' value='{$sourceaddress1}' />"; echo "<input type='hidden' name='sourcename1[]' value='{$income1}' />";
-
A parse error will typically provide more information than that, such as You are trying to use the "rowIDs" POST value as an array on the foreach line. You have defined two fields as "rowID" on your form - but they are not an array. They are instead two separate single entity fields. What will happen in the post data is that the second field's value will overwrite the first field's value. If you want an array to be returned you need to define the fields with array names (note the "[]" in the field name). <!--reseed attribute IDs in case of gap resulting from deletions --> <input type="hidden" name="rowIDs[]" value="{{rowNumber}}" /> Since you are having problems with the POST data names/indexes and the logic to use them, add this on the action page (for debugging purposes) so you can SEE what is being passed. echo "DEBUG POST DATA: <pre>".print_r($_POST, 1)."</pre>";
-
What is the exact error? Please copy/paste it here. EDIT: FYI, are you aware that you are using the exact same variable for all form fields ($nameError) for determining field level errors? <?php if($nameError != '') { ?> <span class="error"><?=$nameError;?></span> <?php } ?> Also, Instead of littering the markup (HTML) with PHP logic, create PHP variables at the top for the error messages, then just output those variables in the markup. E.g. //PHP code at top of script (hint, you could create a function to pass the error message to and have it return back the formatted HTML). $nameErrorOutput = ($nameError != '') ? "<span class='error'>{$nameError}</span>" : ''; $otherfield1ErrorOutput = ($otherfield1Error != '') ? "<span class='error'>{$otherfield1Error}</span>" : ''; $otherfield2ErrorOutput = ($otherfield2Error != '') ? "<span class='error'>{$otherfield1Error}</span>" : ''; //HTML markup at bottom of script <div class="form-group"> <label for="employeename">Employee Name</label><br> <input type="text" name="employeename" id="employeename" style="width:375px;" placeholder="your name..." class="form-control" value="" class="required requiredField" /> <?=$nameErrorOutput?> </div>
-
I don't think this will work: $del_tim_holder_1[count($del_tim_holder_1)] Assuming a zero based index, an array with a count of '3' would have indexes of '0', '1', & '2'. There would be no value with an index of '3'. You could instead use array_pop or, instead of having to use split/explode first to create an array, just use string functions (see example below). Also, rather than only put in the logic for the interval in the function, I would suggest just passing the $del_tim_holder_0 value and have the function do all the logic to return the applicable date string. private function calculateDate($intervalStr) { //Get value following last ':' and ensure a number $inervalWeeks = intval(substr(strrchr($intervalStr, ":"), 1)); //Convert number to weeks $intervalDays = $inervalWeeks * 7; //Create a date intervale $interval = new DateInterval("P{$intervalDays}D"); //Create current date object $currDate = new DateTime(date("d.m.Y")); //Apply the interval and convert to string $newDate = $currDate->add($interval)->format('d.m.Y'); return $newDate; } $del_tim_holder_0 = "15:18:21"; $this->date = $this->calculateDate($del_tim_holder_0); // $this->date = '13.07.2017'
-
It depends on the user workflow. When there are multiple fields needing validation, I would find it more preferable to do the validation on the form submission as opposed to triggering an error on each individual field separately.
-
I'll just say that what you are doing is probably not needed and (if you don't have similar validation on the back end) completely useless. However, your problem is that your current "test" is trying to see if the value contains the entire string of "!\"·$%&/()=?¿@#¬". You need to create a regular expression patter to look for any character. Plus, I suspect one of your other lines in the failure scenario is failing, probably this one document.signup.char_name.focus(); You should pass the form element by reference to the function instead of using getElementById() Also, you should use the onchange event - otherwise the logic will get caught in an infinite loop. When the alert is displayed, the act of the user clicking the OK will initiate another onblur event. function checkInput(inputObj) { var user_input = inputObj.value; var notgood = /[!"·$%&\/()=?¿@#¬]/; if ( !notgood.test(user_input) ) { document.getElementById('submitlink').removeAttribute('disabled'); document.getElementById('badInput').innerHTML = ''; return true; } else { document.getElementById('submitlink').setAttribute('disabled','disabled'); document.getElementById('badInput').innerHTML = 'Bad Input'; alert('Cannot use that character'); inputObj.focus(); return false; } } <input type="text" name="char_name" value="" id="char_name" required="" onchange="checkInput(this);"/>
-
Because the code is creating a new table in the loop for each record. Start the table before your loop. In the loop, output each row. Then after the loop, close the table. As this appears to be an assignment, I will leave it to you to make the modifications.
-
Read the documentation. There is no "one way" that an SDK is used. Nine times out of 10 the SDK file (or the help content/site) will contain a working example.
-
OK, after taking a look afterwards, here is another way without needing to create new objects for each team. Team 1 ID: $matchup->team[0]->attributes()->id OR $matchup->team[0]['id'] Team 2 ID: $matchup->team[1]->attributes()->id OR $matchup->team[1]['id']
-
I think your confusion stems from the fact that the "teams" are separate objects within an array of the match. There may be another way, but it will work if you assign those two array elements of the main object to two new variables/objects, then extract the data there. Also, you can reference the attributes as you have above OR via array indexes which is a little simpler, IMHO. //Load the xml content into object $xmlObj = simplexml_load_file('test.xml'); //Output the week echo "NFL Scheduled Week: {$xmlObj->attributes()->week}<br><br>\n"; foreach($xmlObj as $matchup) { //Display the matchup attributes echo "<b><u>Matchup attributes</u></b><br>"; echo "Kickoff: {$matchup->attributes()->kickoff}<br>\n"; //Object property echo "Game Seconds Remaining: {$matchup['gameSecondsRemaining']}<br><br>\n"; //Array index //Get the team objects from the team array $team1 = $matchup->team[0]; $team2 = $matchup->team[1]; //Display team1 attributes as object properties echo "<b>Team 1:</b><br>\n"; echo "</ul>"; echo "<li>ID: {$team1->attributes()->id}</li>\n"; echo "<li>isHome: {$team1->attributes()->isHome}</li>\n"; echo "<li>score: {$team1->attributes()->score}</li>\n"; echo "<li>rushDefenseRank: {$team1->attributes()->rushDefenseRank}</li>\n"; echo "<li>passDefenseRank: {$team1->attributes()->passDefenseRank}</li>\n"; echo "<li>rushOffenseRank: {$team1->attributes()->rushOffenseRank}</li>\n"; echo "<li>passOffenseRank: {$team1->attributes()->passOffenseRank}</li>\n"; echo "<li>hasPossession: {$team1->attributes()->hasPossession}</li>\n"; echo "<li>inRedZone: {$team1->attributes()->inRedZone}</li>\n"; echo "<li>spread: {$team1->attributes()->spread}</li>\n"; echo "</ul><br>"; //Display team2 attributes as array indexes echo "<b>Team 2:</b><br>\n"; echo "</ul>"; echo "<li>ID: {$team2['id']}</li>\n"; echo "<li>isHome: {$team2['isHome']}</li>\n"; echo "<li>score: {$team2['score']}</li>\n"; echo "<li>rushDefenseRank: {$team2['rushDefenseRank']}</li>\n"; echo "<li>passDefenseRank: {$team2['passDefenseRank']}</li>\n"; echo "<li>rushOffenseRank: {$team2['rushOffenseRank']}</li>\n"; echo "<li>passOffenseRank: {$team2['passOffenseRank']}</li>\n"; echo "<li>hasPossession: {$team2['hasPossession']}</li>\n"; echo "<li>inRedZone: {$team2['inRedZone']}</li>\n"; echo "<li>spread: {$team2['spread']}</li>\n"; echo "</ul><br><hr>\n"; } Output
-
ScoobyDont, Asmac_gyver is alluding to, you are not outputting the HTML correctly to have a "selected" option. It would look like this <option value ="1" selected="selected">Option 1</option> So, you need to get the currently selected value and determine which option to add that parameter to. IMO, this is easiest when the option list is dynamically created. If you have a table to define the options in the DB, then you can use that. Else, you can define an array. Then create a function to create the option list passing the list of available options and the selected option. Also, you can use the same data (DB or array) to validate that the user passed a valid value. function createOptions($options, $selectedValue=false) { $optionsHTML = ''; foreach($options as $value => $label) { $selected = ($value == $selectedValue ) ? ' selected="selected"' : ''; $optionsHTML .= "<option vaue='{$value}'{$selected}>{$label}</option>\n"; } return $optionsHTML; } Usage <?php //In head of document $jobStatuses = array( 'offsite' => 'Off Site', 'onsite' => 'In On Site', 'allocated' => 'Allocated' ); //Get the selected value $selectedJobStatus = //Some code to retrieve selected value //Create job status option list $jobStatusOptions = createOptions($jobStatuses, $selectedJobStatus); ?> <select name="team" class="formfields"> <?php echo $jobStatusOptions; ?> </select>
-
requinex beat me to it, but I'll post the sample code I was working on: <form action="" method="post"> <br/><br/> <h2>Please select issue</h2><br/> <input type="image" src="testing/images/need_toner.png" name="toner"/> <input type="image" src="testing/images/paper_jam.png" name="paper-jam"/><br> <input type="image" src="testing/images/printer_fault.png" name="printer-fault"/> <input type="image" src="testing/images/other.png" name="other"/> </form> if(isset($_POST['toner_x'])) { echo "Perform the Toner action"; } if(isset($_POST['paper-jam_x'])) { echo "Perform the Paper jam action"; } if(isset($_POST['printer-fault_x'])) { echo "Perform the Printer Fault action"; } if(isset($_POST['other_x'])) { echo "Perform the Other action"; } Replace the echo statements with the relevant code for each option. Also, the two "fields" that are returned when clicking a button (fieldName_x 7 fieldName_y) will have values for the x & y positions that the mouse clicked on the relevant image. Put this on your page to "see" how it works: echo "<pre>" . print_r($_POST, 1) . "</pre>";
-
Create classes for the different colors you want. Then have the logic determine which class to use. Or, you can make this much easier by just creating styles named for the brands and then use the dynamic name in defining the class to use. No additional coding needed to set the color: <?php //Test values $row_rsStockDynoFk['vs_brand'] = "Honda"; $row_rsStockDynoFk['vs_yrmodsize'] = "Crx"; ?> <html> <head> <style> .brandHonda { background-color: #FFD9D5; } .brandHusky { background-color: #FED6F5; } .brandKawasaki { background-color: #D6F5D3; } .brandKTM { background-color: #FFE4CA; } .brandSuzuki { background-color: #FFFFD5; } .brandTM { background-color: #D5FFFF; } .brandYamaha { background-color: #DFDFFF; } </style> </head> <body> <div class="lvl1-4-5 brand<?php echo $row_rsStockDynoFk['vs_brand']?>"><?php echo $row_rsStockDynoFk['vs_brand']; ?></div> <div class="lvl1-4-6"><?php echo $row_rsStockDynoFk['vs_yrmodsize']; ?></div> </body> </html>
-
Why would you start with a system designed for a different purpose than the one you need? There are shopping solutions available as well. Start with one of those. It is not as simple as changing an option in the database to change how the application functions. You would have to find all the relevant places in the code to make changes too. A library app is specifically built to have a certain quantity of items that can come and go. A shopping app needs to have an inventory that is reduced as people buy (i.e. check out). but, there will never be a check-in - at least not in the way it would work for a library app. Plus, you will need the ability to add to the inventory and possibly allow back orders, etc. etc. You are only going to find one problem after another. Either find a shopping app that has the right framework to begin with that you can modify or build from scratch.
-
Are the ratings supposed to be unique for each question? For example, for the items A1, A2, A3, & A4 can a user set three of them to a rank of "1" or should one item be 1, another item 2 and a third item 3?
- 1 reply
-
- jquery
- dropdownlist
-
(and 2 more)
Tagged with:
-
Well, I am of the opinion that a project that only requires one developer must not be that significant since it doesn't need experts in various roles (UI development, vs core code development, vs DB design, etc.). So, while it may be hoped that this will be used by millions of users, it doesn't seem like it is being funded as such. If it becomes wildly successful, then the company can hire new people with the right skill-sets to rebuild it correctly. If the current implementation isn't going to be fixed, then I would suggest using the UNION work around.
-
Agreed Jacques1. They are putting the cart before the horse. Only a competent database engineer and appropriate load testing would be able to determine if such an extreme approach is needed. My reasoning for providing the workarounds is that it is not unheard of that those responsible for making decisions don't make the best decisions. E.g. the manager may not have enough technical knowledge and bases the decisions on the developer's opinion or decides that the cost in dollars and time cannot be consumed right now and it isn't work fixing if it "works" right now. So, the OP may be required to find a way to work with what he has been given.
-
That may be, but have you done load testing to know at what point failures will occur and,just as important, where those failures occur? You may be bottle-necked by your storage infrastructure as opposed to the database. My point was there are some instances where having separate databases makes sense, but trying to fix a problem that hasn't been defined/validated is foolhardy. As to your issue, it is difficult to provide a best approach without really understanding the specific problems to solve. But, I can provide some general ideas that may help. Here is the example of one specific problem you posed You state you plan to have millions of users, yet you want to populate a drop-down of all the users in CA. You may want to rethink that - perhaps a search field. Regardless, a more elegant solution would be to only work against a single database at a time. If the DBs for area1, area2, etc. have more meaningful usage for you, then a solution would be to have a "master" database to list out all of the application databases with meaningful names (San Bernadino County, Central CA, etc.). Then, in your admin utility, select the meaningful name which will then set the DB to use. But, if there is no rhyme or reason to the California "areas" you would be stuck with having to run multiple queries and patching the data together or running a complex (potentially performance impacting) query. You should still probably create a master database that has each of the application databases along with a field for the "group" (i.e. California). Then you can have it programatically query all the relevant databases. You can query the same table from multilple databases in one go using the UNION clause: SELECT * FROM db_CA_Area1.users UNION SELECT * FROM db_CA_Area2.users UNION SELECT * FROM db_CA_Area3.users UNION SELECT * FROM db_CA_Area4.users . . . etc. However, I give no promises that the performance of this with ~10 databases would be acceptable.
-
I see. I was expecting to see the placeholders as well.