Jump to content

DavidAM

Staff Alumni
  • Posts

    1,984
  • Joined

  • Days Won

    10

Everything posted by DavidAM

  1. In HTML 4.01 Strict, the W3C Validation Service will produce warnings and errors if the "self-closing" tag is used. This style is defined for XHTML and HTML5
  2. When you are going to drop out of PHP in an IF statement, you have to use the curly braces. You have done this everywhere except in the if ($jenis=="4") condition. So that one would throw an error. Looks like you put the closing brace in, so you are missing an open-brace. Rather than do a bunch of if-else statements, this might be easier to code and read if you use a switch statement and don't drop out of PHP. while ($row = mysql_fetch_array($query)){ echo 'Student ID: '.$row['student_id']; echo '<br/> Fullname: '.$row['fullname']; echo '<br/> IC No.: '.$row['ic_number']; echo '<br/> Course: '.$row['course']; echo '<br/> Type Of Letter: '.$row['jenissurat']; echo '<br/><br/>'; $jenis=$rows['jenissurat'] switch($jenis) { case "1": echo '<a href="PHPWord/PengesahanBelajar-code.php">Generate Letter</a>'; break; case "2": echo '<a href="PHPWord/KebenaranProjek-code.php">Generate Letter</a>'; break; case "3": echo '<a href="PHPWord/PelepasanExam-code.php">Generate Letter</a>'; break; case "4": echo '<a href="PHPWord/TamatBelajar-code.php">Generate Letter</a>'; break; } }
  3. That query will select 1 random row from the table and return it That is not a random selection. To do that, you will have to keep track of each row that is returned and exclude it from the selection until all of the rows are excluded. Then remove the exclusions and begin again So, on the 11th run, what happens? Does the query fail? Of course it will return the same row twice! It is even conceivable that it will return the same row twice in succession.
  4. Typically, you would put the ID in the value attribute of the OPTION tag. Then the form sends the ID of the selected entry. If you want to display the name, you would look it up using the (unique) ID. To solve the change on submit, that's a new page load, you have to add the "SELECTED" attribute to the OPTION tag that was selected last time around. $idSelectedByUser = (isset($_GET['propType']) ? $_GET['propType'] : ''); echo "<select id='propType' name='propType'>"; foreach($propType as $pType) { echo "<option name='" . $pType->name . "' value='" . $pType->id . "'" . ($pType->id == $idSelectedByUser ? " SELECTED='SELECTED' " : "") . ">" . $pType->id . " - " . $pType->name . "</option>"; } echo "</select>";
  5. The http specifications recommend using GET for retrieving content (i.e. the user wants to "get" a page) and using POST for actions that will change something (i.e. Insert, update, delete data). The maximum allowed length of the URL is limited (by the http specification), so if you are submitting data such as this post here, using GET may result in the data being truncated (chopped-off) or the request failing entirely. (Note that the maximum size of POST data is also limited. But that limitation is a configuration setting on the server and may be modified.) The URL string can be copied, bookmarked, and even emailed to other people. It might even get indexed by a search engine. If that happens, all of the data is in the url and the data update would be performed again. If you have a Search Form that is a separate "page" from the results page or an alternate route to the results page; you could use GET with the form. Then the fields are in the URL where the results script expects them. Perhaps the results page also allows some search refinement, or pagination, which is handled as a hyperlink and not as a form, so it is added to the url string. @SocialCloud: That really makes no sense at all. Users can modify the GET request just as easily. And it is contrary to the specification -- actions should use POST. And regardless of what method is used, the script should verify that the user has permissions to perform the action. And if the user has permission, it really does not matter that they supplied the ID by trickery.
  6. The $EMail variable has not been defined, and therefore has no value.
  7. 1) Be aware that the user can disable Javascript, which means none of your validations will run. It is OK to validate using Javascript for the purpose of giving the user a quicker negative response however you absolutely must validate (again) on the server using PHP. 2) PHP runs on the server. It is done and has gone away before the browser ever gets the page to display. So, in fact, you cannot "integrate PHP into form validation" (on the client side). In order to "integrate" them, the browser makes a call to the server which will run a PHP script and send a result. This is usually handled using AJAX (Asynchoronous Javascript and XML).
  8. If you are using Apache, you want to look at mod_rewrite.
  9. Look closely at that. There is no "userfile[]" type for an INPUT tag. You need to have multiple "INPUT type=file" tags, all with the same name; a name that ends with the square-brackets. This will produce an array in the $_FILES array with (essentially) an entry for each file that is uploaded. You will have to walk through that array and process each file. I really don't see how this is going to work. You are UPDATEing the users record for the current user. So no matter how many files you allow them to upload ONLY THE LAST ONE will be in the database when all is said and done.
  10. You seem to be asking TWO different questions: To me, this says I want: UserA UserA@Address MyShop 123 UserB UserB@Address AShop 124 One row per user with the total number of comments across all items belonging to that user (not including comments from that user) While this implies you were looking for UserA UserA@Address MyShop UserB 23 UserA UserA@Address MyShop UserC 77 UserA UserA@Address MyShop UserD 23 Multiple rows for each SELLER with a row for each user who has commented on the seller's items, showing the number of comments for each user Those are two distinctly different queries.
  11. You have TWO separate forms there. When a submit button is clicked, only the form containing THAT button is submitted and only the fields IN THAT FORM are submitted. To upload multiple files, you have to have multiple FILE-type fields in the form with different names (or as an array). See the manual Multiple File Uploads <form method='post' action='upload.php' enctype='multipart/form-data'> <input type='file' name='filename1' class="browse" /> <input type='file' name='filename2' class="browse" /> <input type="submit" value="Upload" class="submit-button" /> </div> </form> On a side note: I don't see any reason for this to be done in TWO separate queries: $sql = "UPDATE users SET logo = '". mysql_real_escape_string($n) ."', " . " logoone = '" . mysql_real_escape_string($n) ."' " . "WHERE id='".$_SESSION['userID']."'";
  12. Since you are not sending any parameters, you can easily type that address into your browser and see what you are getting back. Be sure to use the "View Source" feature of the browser, in case the returned data contains HTML markup. I see there is a space in that url. I have always avoided that. I don't know if that is a problem or not. Also, that url is not qualified (no scheme or domain) so the browser is sending it relative to the page you are on. You'll have to provide the full url for the test mentioned above; and probably should provide a full url for the AJAX request as well. Oops, I see you changed it in your most recent post: Try typing that, "http://localhost/test/test.php", directly in the browser and see what comes back. Also, what headers are you getting? Some of them may be pertinent to the problem (i.e. cacheing, etc).
  13. Maybe something like this? function swap() { i++; if (i%2) { fadeSwap(500, 'http://www.collectiondx.com/files/BatmanARTFX5.JPG'); } else { fadeSwap(500, 'http://ecx.images-amazon.com/images/I/41Wm2rA8sbL._SL500_AA300_.jpg'); } } function fadeSwap(ms, img) { var fadeChange = -0.1; // Start by Fading OUT var newImage = img; // Hold the new image file name var opacity = document.getElementById("gallery").style.opacity = opacity; // Get the Current opacity function doFadeSwap() { if (opacity <= 0) { // The image is faded out completely document.getElementById("gallery").src = newImage; // Swap the image fadeChange = +0.1; // Change Direction (now we'll fade in) } else if (opacity >= 1) { // The image is faded in completely window.clearInterval(fadingSwap); // Stop the timer } opacity += fadeChange; // Increase or Decrease the Opacity document.getElementById("gallery").style.opacity = opacity; } var fadingSwap = window.setInterval(doFadeSwap, ms); } Remember, I warned you, I'm not great with JS
  14. I don't see how it is returning any different results. It is exactly the same query, and basically the same process. We just changed the conditions for entering the loop. The code ... Oh, I see. I had left out the assignment statements that were getting the data from $row2. Those need to be in there. All of those navigation sections look like exactly the same code, except for the selection criteria. Anytime you have code repeated, you can improve it by turning it into a function. For instance, add this function to the page (at the bottom is fine): function pageNavUL($piSection) { $column = 'myPageNav' . $piSection; $out = ''; $sql = "SELECT id, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE $column='$piSection' AND myPageActive='Yes' ORDER BY listorder"; $res = mysql_query($sql); if ($res) { if (mysql_num_rows($res)) { $out .= "<ul class='mm-footer-ul'>"; while ($row = mysql_fetch_assoc($res)) { $id = $row2['id']; $myPageURL = $row2['myPageURL']; $myButtonTitle = $row2['myButtonTitle']; $myTitle = $row2['myTitle']; $out .= "<li class='mm-footer-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } mysql_free_result($res); $out .= "</ul>"; } } return $out; } Then you can replace each of the NAV sections with something like this: /* TOP NAVIGATION */ <?php echo $pageNavUL(1); ?> <header class="mm-header mm-replace"> [edit]Also, get in the habit of using FULL PHP TAGS <?php. The short ones can create problems for you in the future.[/edit]
  15. Glad I could help. Welcome to the world of programming. Where the only thing that is constant, is change. If that solves your problem, go ahead and click the "Mark Solved" button at the top of the page. Hmm, if I put a "!" in front of my name, I wouldn't know who I am. !DavidAM
  16. You are executing the query twice, now. Apparently so you can check to see if there is data returned? $sql = "SELECT ..."; $res = mysql_query($sql); if ($res) { if (mysql_num_rows($res)) { echo '<UL>'; while ($row = mysql_fetch_assoc($res)) { echo '<LI> ...</LI>'; } mysql_free_result($res); echo '</UL>'; } }
  17. You are only fetching the first row. Try $num=mysql_num_rows($results); $i=0; while ($i < $num) { $array = mysql_fetch_array($results); # <== Fetch a row of data echo $array['playerName']; $i++; }
  18. Sorry, you're right. It should be $strBuff = $strBuff . Chr($B & 0xFF);
  19. The call to fadeOut() will return immediately while the "fading" is being processed by a timer element. The image will be swapped and fadeIn() will be called; this function will also return immediately. At which point, you have two (asynchronous) timers running, one reducing the opacity, and the other increasing the opacity. That's the problem. Sadly, I don't have a solution for you. I don't do much in Javascript, and when I do, I use JQuery as much as possible.
  20. Ahh, VB6! Takes me back to my younger days ... I think this would do it. $Username = "Peter Piper"; $CallSign = "aa4aa"; $CallSign = strtoupper($CallSign); #force uppercase callsign If strlen($Username) { ## or use: if (! empty($Username)) $strBuff = ''; ## Avoid an undefined variable Notice later for ($A = 0; $A < strlen($CallSign); $A++) { ## NOTE Start at Zero NOT One $B = ord(substr($CallSign, $A, 1)); $B = $B + ord(substr($Username, ($A % strlen($Username)) + 1, 1)); ## % is Mod $strBuff = $strBuff . Chr($B & &HFF); ## NOTE concatenation is . (dot) // & is bitwise And } } Else { $strBuff = $CallSign; } That could be optimized a bit, but I wanted to keep it as close to the original code as possible so you can see the differences. I added comments about some significant points
  21. Get rid of the hidden field, you don't need it. Put to record's ID in the name of the checkbox: echo "<input type='checkbox' name='answered[$id]' /></p>" Then process the answered array: if (isset($_POST['answered'])) { foreach ($_POST['answered'] as $id => $value) { UPDATE ... WHERE id = $id } } Note: Checkboxes are only POSTed if they are actually checked. So, if none are checked, the "answered" element of the POST array will not exist.
  22. All errors matter! That includes Warnings and Notices. These all stem from problems in the code. That notice indicates you tried to retrieve a value from an element of an array and the element was not defined. Which means you did not get the value from the array, you got a NULL value. @OP: Post that section of the code and we can help. Usually this kind of thing comes from trying to retrieve a value from the session that has not been put into the session because it is the visitors first visit. You usually want to apply some meaningful default value as in: if (isset($_SESSION['username'])) $displayName = $_SESSION['username']; else $displayName = 'Guest'; which can be shortened using the ternary operator to: $displayName = (isset($_SESSION['username']) ? $_SESSION['username'] : 'Guest');
  23. Without more detail, it is hard to be specific. One of the following may be possible: 1) If you have any influence over the export (from Access) ask them to export as "Y-M-D", then change the datatype on your column and import. 2) If the import (to mySql) is a PHP script, put the STR_TO_DATE call in the INSERT statement and change the datatype. 3) If the import is a mySql LOAD DATA statement, change the column name to invoiceDateMDY (or something) then add another column at the end of the row as invoiceDate DATE DEFAULT NULL. After each import run an update UPDATE table SET invoiceDate = STR_TO_DATE(invoiceDateMDY, "%m/%d/%y") WHERE invoiceDate IS NULL. Eventually, you can drop the invoiceDateMDY column from the table. (I have not used LOAD DATA much, and I don't know if it will import fewer columns than exist in the table, but it is worth a try) Be sure to add an INDEX on the true invoiceDate column.
  24. When I'm doing drop-downs, I return an associative array, with the database unique ID as the key and the value as the, well ... value. function dropdownList($dbConn, $table, $idCol, $valueCol) { $sql = "SELECT $idCol, $valueCol FROM $table ORDER BY $valueCol"; $res = $dbConn->query($sql); if (! $res) { # For development ... trigger_error('dropdownList query failed with error: ' . $dbConn->error() . ' -- ' . $sql, E_USER_ERROR); # ... in Production we need to handle the error or return an empty array return array(); } $out = array(); while ($row = $res->fetch_assoc()) { $out[$row[$idCol]] = $row[$valueCol]; } return $out; } Disclaimer: Off the top of my head. Not Tested To use the data: $list = dropdownList($mysqli, 'Categories', 'ID', 'CategoryName'); $html = '<SELECT name="category">'; foreach ($list as $id => $value) { $html .= '<OPTION value="' . $id . '">' . htmlspecialchars($value) . '</OPTION>'; } $html .= '</SELECT>'; echo $html; Something like that
  25. Since you are doing a conversion (STR_TO_DATE) on the date column, I'm pretty sure the index would be useless. You need to store the dates as a DATE datatype. Then an index could be used for the BETWEEN. As it is, the server is going to do a table scan (read through every row in the table) for both of the derived tables (the LEFT JOIN sub-queries), and convert every invoice date in the database (twice since you have two joins).
×
×
  • 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.