Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. You really need to rethink how you are going to generate "random" colors. You are going to generate colors that will not be readable on whatever background you choose. If you are using a white background maybe limit it to only 0-9 for darker colors.
  2. You want to run ONE query. Not two queries. Not multiple queries in loops. One Query. SELECT card.event_id, card.qty, card.event, events.spots, events.name FROM card JOIN events ON events.id = card.event_id Did I mention that you only need to run ONE query?
  3. Everyone is entitled to their opinion. My opinion is that some empty SPAN tags would not be an issue. It is just some simple ASCII text and wouldn't have any real effect on the time to download the page and the overhead to display the page wouldn't be affected either that anyone could ever notice. It is much more efficient to add text to an existing SPAN than adding a bunch of text nodes. Also, by adding text nodes, if a user fixes one problem but makes a different error how do you remove the first error? You would now have to add an ID to those text nodes so you can remove them. By just updating a span you can clear/populate that field very simply. Here is a quick/rough rewrite for one possible solution <html> <head> <script type="text/javascript"> function validate_form(formObj) { var errors = false; //name validation var nameErrText = ""; var fieldset_name = document.getElementById("fieldset_name"); if(fieldset_name.value.length <= 2) { nameErrText = "Please populate your name!"; } if(nameErrText != "") { errors = true; } document.getElementById('fieldset_name_error').innerHTML = nameErrText; //Email validation var emailErrText = ""; var fieldset_email = document.getElementById("fieldset_email"); var re = /^[a-z]+[a-z0-9.]+@{1}[a-z0-9\-]+[.]{1}[a-z]{1,5}[a-z.]{1,5}?[a-z]$/i; if(!fieldset_email.value.length) { emailErrText = "Please enter an email address"; } else if(!re.test( fieldset_email.value)) { emailErrText = "Please enter a valid email!"; } if(emailErrText != "") { errors = true; } document.getElementById('fieldset_email_error').innerHTML = emailErrText; //Message validation var messageErrText = ""; var fieldset_message = document.getElementById("fieldset_message"); if(fieldset_message.value.length < 1) { messageErrText = "Please populate your message!"; errors = true; } if(nameErrText != "") { errors = true; } document.getElementById('fieldset_message_error').innerHTML = messageErrText; //Return true/false based upon whether there were errors return (!errors); } </script> <style> .error { color: #ff0000; } </style> </head> <body> <form onsubmit="return validate_form(this);" method="POST"> Name: <input type="text" name="fieldset_name" id="fieldset_name" /> <span class="error" id="fieldset_name_error"></span><br> Email: <input type="text" name="fieldset_email" id="fieldset_email" /> <span class="error" id="fieldset_email_error"></span><br> Message:<br> <textarea name="fieldset_message" id="fieldset_message"></textarea> <span class="error" id="fieldset_message_error"></span><br> <button type="submit">Submit</button> </form> </body> </html>
  4. Instead of using "createTextNode" and "appendChild" to add the error message, I would create an empty span next to each input field with an ID associate with each field. Then if there is an error, populate the span with the error message. Plus, it looks like to stop at the first error instead of showing all the errors which is a poor implementation in my opinion.
  5. if(up){$year++;} if(dn){$year--;} 'up' and 'dn' are not valid variables. Also, if your intent is to let the user continuously increment/decrement the $year then you need to pass something other than whether the user select up or down. I suspect you start $year as the current year and want to allow the user to continue to increment and decrement. So, you should instead pass a value of how many years to increment or decrement from the default. This is very easy to do with $_GET or $_POST Here is an example page on how you can do this using GET or POST <?php error_reporting(E_ALL); session_start(); $current_year = date('Y'); //Determine year if using POST method $postOffset = isset($_POST['post_offset']) ? intval($_POST['post_offset']) : 0; if(isset($_POST['dn'])) { $postOffset--; } if(isset($_POST['up'])) { $postOffset++; } $postYear = $current_year + $postOffset; //Determine year if using GET method $getOffset = isset($_GET['get_offset']) ? intval($_GET['get_offset']) : 0; $getYear = $current_year + $getOffset; $getLast = $getOffset - 1; $getNext = $getOffset + 1; ?> <html> <head></head> <body> POST Year: <?php echo $postYear; ?><br><br> <form action="" method="post"> Change the year using $_POST<br> <input type="hidden" name="post_offset" value="<?php echo $postOffset; ?>" /> <input type='submit' name='dn' value='Last Year'/> <input type='submit' name='up' value='Next Year'/> </form> <br><br><br><br> Get Year: <?php echo $getYear; ?><br><br> Change the year using $_GET<br> <a href="?get_offset=<?php echo $getLast; ?>">Last Year</a> <a href="?get_offset=<?php echo $getNext; ?>">Next Year</a> </form> </body> </html>
  6. Why is this post in PHP Help? Your post makes absolutely no sense. You apparently have an idea in your head, but you failed in trying to convey that idea. If you are going post something that you want ta response to, at least take the time to actually understand what you are posting. $num1=ROUND(1,5), $num2=ROUND(1,5), Aside from the fact that you couldn't be bothered with writing simple code without syntax errors, it appears you do not know what ROUND() does. I really have no clue what your proposal is because you make no sense. But, it seems you will display some number(s) to the user and expect them to click certain checkboxes. And, that would work. But, here's the catch. There are hundreds of "simple" solutions such as that which will work. They will work because they are not common. If that process was to become common place OR if someone specifically wanted to hack your site, internet miscreants would be able to throw together a script to circumvent that process in a few minutes. Even Jessica's solution could be very easily circumvented. But, as long as it is not a common preventative measure and your site is not being specifically targeted it will work. One that I have used in the past is an onclick event in the textarea of a form to populate a hidden field (which gets checked on the receiving page). Just like Jessica's solution, this requires no additional work by the user. In 99% of cases they will click in that field to enter their response. If the user doesn't click it would let them know. Captcha's have been a "good" solution that can be easily implemented as a standard. But, the problem is that OCR readers have gotten better and better to the point where I can't even understand what characters are in the freakin image. So, I thin there does need to be a new standard. But, the solutions we are proposing will not work as a standard.
  7. Your post title and first two posts were about any ARRAY and your last post is using a while() loop from a database result. Those are very different things. Doing what you want with an array is very easy using array_chunk(). foreach(array_chunk($array, $column) as $row) { echo "<tr>\n"; foreach($row as $item) { echo "<td>{$item}</td>\n"; } echo "</tr>\n"; } Of course, you could always dump the DB results into an array first.
  8. I'm not following. Are you including a URL from an external site for an image on your page and sometimes that URL isn't to a valid image?
  9. I believe this is the ONE query you should be running SELECT p.category, p.downloads, p.views, p.title, p.caption, , p.image, p.placement, p.teammember1, p.teammember2, p.teammember3, p.otherpeople, t.boat, t.teammember1, t.teammember2, t.teammember3, t.channel, t.flathead, t.blue, t.total, t.bigfish, t.totalweight FROM photogallery AS p LEFT JOIN tourneyresults AS t ON p.year = t.year AND p.timeofday = t.timeofday AND p.placement = t.placement WHERE p.year = ? AND p.timeofday = ? AND p.status = 1 AND p.placement <> "" ORDER BY p.category, p.placement
  10. You are not understanding my question. You have two sections of code; one which is only executed if $placement is not empty and the other which is always executed. So, you obviously want something to be different when $placement is empty. I doubt that the problem with $allteammembers is really the only problem.
  11. Another thing. I see that you are defining links ($link1, $link2, etc) using the process $link1 = addplus($member1); Question: if $member1 is anything other than an empty value, will the returned value ever be empty? The reason I ask is you have a ton of conditional statements such as if ((!empty($member1)) && (!empty($link1))) But, if $link1 would only be empty if $member1 is empty then you only need to check the member variable
  12. Well, line 49 is INSIDE the conditional block of code and line 60 is OUTSIDE that conditional block of code. I can provide some sample code, but YOU need to state what you want to do differently for records where $placement is empty. Right now we know that you are not setting $allteammembers if placement is empty and you apparently don't want to be doing that based on your comments.
  13. So what - EXACTLY - are you wanting to do differently if $placement is empty?
  14. I can't really determine what you want to do based upon your current code. When you say "move $allteammembers out of the "if statement"?" that doesn't say WHICH line you moved out. Here is your current code with some indenting to show the logical structure. You can see which lines of code are executed when $placement is empty and which lines are not. <?php $query = "SELECT title, caption, category, image, placement, teammember1, teammember2, teammember3, otherpeople, downloads, views FROM photogallery WHERE year = ? AND timeofday = ? AND status = 1 ORDER BY category, placement" if ($stmt = $mysqli->prepare($query)) { $stmt->bind_param('is', $year, $timeofday); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($title, $caption, $category, $image, $placement, $teammember1, $teammember2, $teammember3, $otherpeople, $downloads, $views); while($stmt->fetch()) { if ((!empty($placement))) { ############################################################### ## THE CODE IN THIS SECTION IS ONLY RUN FOR THE CONDITION ABOVE ############################################################### $query = "SELECT boat, teammember1, teammember2, teammember3, channel, flathead, blue, total, bigfish, totalweight FROM tourneyresults WHERE year = ? AND timeofday = ? AND placement = ?" $stmt2 = $mysqli->prepare($query); $stmt2->bind_param('isi', $year, $timeofday, $placement); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($boat, $member1, $member2, $member3, $channels, $flatheads, $blue, $total, $bigfish, $weight); $stmt2->fetch(); $stmt2->close(); $link1 = addplus($member1); $link2 = addplus($member2); $link3 = addplus($member3); if ((!empty($member1)) && (!empty($link1))) {$member1 = "<a href='$mainurl/fisher/$link1'>$member1</a>";} if ((!empty($member2)) && (!empty($link2))) {$member2 = "and <a href='$mainurl/fisher/$link2'>$member2</a>";} if ((!empty($member3)) && (!empty($link3))) {$member3 = "and <a href='$mainurl/fisher/$link3'>$member3</a>";} if ($boat) {$boat2 = "~ Boat #$boat";} else {$boat2 = "";} if ($channels) {$channels2 = "$channels Channel(s)";} else {$channels2 = "";} if ($flatheads) {$flatheads2 = " | $flatheads Flathead(s)";} else {$flatheads2 = "";} if ($blue) {$blue2 = " | $blue Blue(s)";} else {$blue2 = "";} if ((!empty($member1)) && (!empty($link1))) { $allteammembers = "<b>Team Members: </b>$member1 $member2 $member3 $boat2<br><span style=\"padding-left: 20px\">Caught: $channels2$flatheads2$blue2</span><br><br>"; } else { $allteammembers = ""; } } ############################################################### ## THE CODE IN THIS SECTION IS RUN FOR EVERY RECORD ############################################################### $link5 = addplus($teammember1); $link6 = addplus($teammember2); $link7 = addplus($teammember3); if ((!empty($teammember1)) && (!empty($link5))) { $teammember1 = "<a href='$mainurl/fisher/$link5'>$teammember1</a>"; } if (!empty($teammember2) && !empty($link6)) { $teammember2 = "and <a href='$mainurl/fisher/$link6'>$teammember2</a>"; } if (!empty($teammember3) && !empty($link7)) { $teammember3 = "and <a href='$mainurl/fisher/$link7'>$teammember3</a>"; } if ((!empty($teammember1)) && (!empty($link5))) { $teammemberspictured = "<b>Team Members Pictured: </b>$teammember1 $teammember2 $teammember3<br>"; } else { $teammemberspictured = ""; } if ((!empty($otherpeople)) && (((!empty($teammember1)) && (!empty($link5))) || ((!empty($member1)) && (!empty($link1))))) { $otherpeople2 = "<b>Other People in This Photo:</b> $otherpeople<br>"; } if (!empty($otherpeople) && ((empty($teammember1)) && (empty($link5))) && ((empty($member1)) && (empty($link1)))) { $otherpeople2 = "<b>People in This Photo:</b> $otherpeople<br>"; } if (($category == "0") || (empty($category))) {$category2 = "No Category";} if (($category == "1")) {$category2 = "First Place Winner";} if (($category == "2")) {$category2 = "2nd-5th Place Winners";} if (($category == "3")) {$category2 = "6th-12th Place Winners";} if (($category == "4")) {$category2 = "13th-20th Place Winners";} if (($category == "5")) {$category2 = "13th-24th Place Winners";} if (($category == "6")) {$category2 = "Big Fish Winners";} if (($category == "7")) {$category2 = "Take Off";} if (($category == "8")) {$category2 = "Weigh In";} if (($category == "9")) {$category2 = "Scoreboard";} if (($category == "10")) {$category2 = "Prizes from Drawing";} if (($category == "11")) {$category2 = "Kids Prizes and Face Painting";} if (($category == "12")) {$category2 = "Morning Meeting";} if (($category == "13")) {$category2 = "Sign Up";} if (($category == "14")) {$category2 = "Spectators";} if (($category == "15")) {$category2 = "Misc.";} if (($category == "16")) {$category2 = "Extra Photos";} if ($timeofday == "night") {$subfolder = "NightTourney";} else {$subfolder = "year";} ECHO<<<END <div class="gallery" id="container"> <div id="left"> <img src="$mainurl/images/$subfolder/$year/$image"> </div> <div id="bottom"> $category2 | <a href="$mainurl/images/year/$year/$image" class='links'>Download Image</a> | $downloads downloads | $views views | Report Error | Add A Comment </div> <div id="right"> <h3>$title</h3> $allteammembers $teammemberspictured $otherpeople2 <p>$caption</p> </div> </div> END; } $stmt->close(); }
  15. Your code is a really hard to "read" because there is no structure (although that might be a copy/paste error). But, if you were to properly structure the code you it seems that about 1/2 of that logic is dependent upon this condition if ((!empty($placement))) So, the part to set $allteammembers is within that condition, but the logic to display the output is NOT within that condition. So, if $placement is empty $allteammembers is not being evaluated, but the code to output that value is still executed - so it will display the value from the last record. EDIT: You are also running a second query within the loop. You should never run queries in loops. In this case you should be running ONE query with a JOIN statement. EDIT#2: It's not clear whether you WANT to entirely skip records where $placement is empty or not. If so, then your query should be excluding those records.
  16. Because you are only passing a file name to the function file_exists(). You need to tell it "where" to look. Your comment states: // Set this to false if the file already exists So, I assume you should be looking in the folder where you store these files after upload, i.e. $upload_dir
  17. Personally, I agree with Jessica, if someone can access your RAM then this discussion is pointless. That person could implement a type of man in the middle attack to get the password before it is even stored in memory. If someone has access to query the memory on the machine, then they could just as easily modify the PHP files to display/store the password where they can get at it. But, you already stated the PW is stored in a file, so it would be a heck of a lot easier for that malicious user to get the PW there rather than interrogating the memory space. But, for the sake of argument, take a look at this post: http://stackoverflow.com/questions/7244395/how-to-overwrite-php-memory-for-security-reason
  18. FYI: You can greatly reduce that code (and implement trim): $sha1_array = array_map('sha1', array_map('trim', explode("\n", $_POST['passwords']))); echo print_r($sha1_array);
  19. Radio buttons are a bit tricky. There is no way to directly get the value of the selected radio button option. You have to check to see which one is checked and then get the value of that option. So, right now you are getting the first value in the radio group - regardless which one is checked (or not checked). I have a function I built to do just that. Plus, you cannot have multiple elements on a page with the same ID! You will need to reference the radio group by Name. I fixed some other things as well <html> <head> <script type="text/javascript"> function radioGroupValue(groupObj) { if (!groupObj.length) { //Only one option in group, return value if checked return (groupObj.checked) ? groupObj.value : false; } for (var i=0; i<groupObj.length; i++) { //Multiple options, return value of checked option if (groupObj[i].checked) { return groupObj[i].value; } } //No option was selected return false; } function updateTotal() { //Calculate product price var product_total = 0; var dateFields = document.getElementsByName('date[]'); for(var i=0; i<dateFields.length; i++) { product_total += dateFields[i].checked ? parseInt(dateFields[i].getAttribute('data-price')) : 0; } //Calculate pages price var pages_total = parseInt(document.getElementById('pages').value); //Calculate packages price var packages_value = radioGroupValue(document.getElementsByName('packages')); var packages_total = (packages_value) ? parseInt(packages_value) : 0; //Calculate total price var total_price = product_total + pages_total + packages_total; //Fill form fields document.getElementById('productPrice').value = product_total; document.getElementById('pagesPrice').value = pages_total; document.getElementById('packagePrice').value = packages_total; document.getElementById('totalPrice').value = total_price; } </script> </head> <body> <table> <tr> <td id="datecontainer" onchange="Process(this.options[this.selectedIndex].value)"> <input id="date0" type="checkbox" name="date[]" value="blue" data-price="10" onChange="updateTotal();" />product 1(10)<br /> <input id="date1" type="checkbox" name="date[]" value="green" data-price="30" onChange="updateTotal();" />product 2(30)<br /> <input id="date2" type="checkbox" name="date[]" value="red" data-price="50" onChange="updateTotal();" />product 3(50)<br /> </td> <tr> <td> Total cost Product: <input name="total" id="productPrice" type="text" readonly="readonly" /> </td> </tr> <tr> <td> Pages Price <select id="pages" style="width:205px" onchange="updateTotal()"> <option value="0">Select Pages</option> <option value="5">5 Pages</option> <option value="10">10 Pages</option> <option value="15">15 Pages</option> <option value="25">25 Pages</option> <option value="30">30 Pages</option> <option value="100">More than 35 Pages</option> </select> </td> </tr> <tr> <td> Total cost Pages: <input name="pagesprice" id="pagesPrice" type="text" readonly="readonly" /> </td> </tr> <tr> <td>Package <input type="radio" name="packages" id="packages0" value="100" onclick="updateTotal();" />50MB <input type="radio" name="packages" id="packages1" value="200" onclick="updateTotal();" />100MB <input type="radio" name="packages" id="packages2" value="300" onclick="updateTotal();" />200MB </td> </tr> <tr> <td> Total Package Cost: <input name="packagecost" id="packagePrice" type="text" readonly="readonly" /> </td> </tr> <tr> <td> Total Pagesprice+Total cost Product+Total Package Cost <input name="totalprice" id="totalPrice" type="text" readonly="readonly" /> </td> </tr> </table> </body> </html> EDIT: Why do you have an onchange event tied to a TD element?
  20. Basically, you just need to give the option "Select Pages" a value of 0 to correct that error (or add more code to the function to handle that scenario). Anyway, this is a bit cleaner <html> <head> <script type="text/javascript"> function updateTotal() { var date0 = document.getElementById('date0'); var date1 = document.getElementById('date1'); var date2 = document.getElementById('date2'); var amount = 0; amount += date0.checked ? parseFloat(date0.getAttribute('data-price')) : 0; amount += date1.checked ? parseFloat(date1.getAttribute('data-price')) : 0; amount += date2.checked ? parseFloat(date2.getAttribute('data-price')) : 0; var totalpages = parseInt(document.getElementById('totalpages').value); document.getElementById('total').value = amount; document.getElementById('pagesprice').value = totalpages; document.getElementById('totalprice').value = amount + totalpages; } </script> </head> <body> <table> <tr> <td id="datecontainer" onchange="Process(this.options[this.selectedIndex].value)"> <input id="date0" type="checkbox" name="form[date]" value="blue" data-price="10" onChange="updateTotal();" />product 1(10)<br /> <input id="date1" type="checkbox" name="form[date]" value="green" data-price="30" onChange="updateTotal();" />product 2(30)<br /> <input id="date2" type="checkbox" name="form[date]" value="red" data-price="50" onChange="updateTotal();" />product 3(50)<br /> </td> <tr> <td> Total cost Product: <input name="total" id="total" type="text" readonly="readonly" /> </td> </tr> <tr> <td> Pages Price <select id="totalpages" style="width:205px" onchange="updateTotal()"> <option value="0">Select Pages</option> <option value="5">5 Pages</option> <option value="10">10 Pages</option> <option value="15">15 Pages</option> <option value="25">25 Pages</option> <option value="30">30 Pages</option> <option value="100">More than 35 Pages</option> </select> </td> </tr> <tr> <td> Total cost Pages: <input name="pagesprice" id="pagesprice" type="text" readonly="readonly" /> </td> </tr> <tr> <td> Total Pagesprice+Total cost Product <input name="totalprice" id="totalprice" type="text" readonly="readonly" /> </td> </tr> </table> </body> </html>
  21. Right, but since he only wants the average of the rows where company = 84 he wouldn't need the GROUP BY, just a where clause @1internet, this will give you the average for a particular office SELECT AVG(review) WHERE company = 84 OR you could run a query to get the average of every office (using GROUP BY as Requinex suggested) SELECT company, AVG(review) as average GROUP BY company
  22. That will not send those values in the query string (myvar & mayvar2) as POST variable. They will still be in the $_GET array. To have them sent as POST vars you need to put them as input fields in the form.
  23. Ah, ye of little faith. Don't give up at the first impediment. I'm not sure what you mean by "Our call center software has the ability to preload web addresses if the operator hits a hot key . . ." Not sure what you mean by "preload". But, no matter. I will assume that all you have the ability to do is send a URL for the support rep to open in their browser. I will also assume that you will be appending in that URL the credentials for the customer's account. So, you can pass the credentials to the support rep via a URL, but the credentials need to be sent to the login page via POST. No problem. Create an intermediary page. So, let's say the login page that receives the POST data is login.php. Create a new page called support_login.php and create the URL to that page along with the parameters for the credentials. Then create that page something like this: <html> <body> <form action="login.php" method="post"> Username: <input type="hidden" name="username" value="<?php echo $_GET['uname']; ?>" /><br> Password: <input type="hidden" name="username" value="<?php echo $_GET['pword']; ?>" /><br> <button type="submit">Login As User</button> </form> </body> </html> Now, that's an oversimplification of what I would really do. I'd definitely add some validation of the parameters. And, I might pass a parameter to display the account number/name to the page as well so the support rep can confirm the account before logging in. But, that should give you the idea.
×
×
  • 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.