Jump to content

hitman6003

Members
  • Posts

    1,807
  • Joined

  • Last visited

Everything posted by hitman6003

  1. <?php if (isset($_POST['Search'])) { $query = "SELECT * FROM jobs WHERE "; // Check for an location. if (!empty($_POST['location'])) { $query .= "location = '" . mysql_real_escape_string($_POST['location']) . "'"; $search = TRUE; } // Check for a category. if (!empty($_POST['category'])) { if (!empty($_POST['location']) { $query .= " AND "; } $query .= "category = '" . mysql_real_escape_string($_POST['category']) . "'"; $search = TRUE; } $query .= "ORDER BY job_id DESC"; } // or if (isset($_POST['Search'])) { $where = array(); // Check for an location. if (!empty($_POST['location'])) { $where[] .= "location = '" . mysql_real_escape_string($_POST['location']) . "'"; $search = TRUE; } // Check for a category. if (!empty($_POST['category'])) { $where[] .= "category = '" . mysql_real_escape_string($_POST['category']) . "'"; $search = TRUE; } $query = "SELECT * FROM jobs WHERE " . implode(" AND ", $where) . " ORDER BY job_id DESC"; }
  2. the load time will change, depending on a lot of different things (server load primarily...especially with shared hosting). You are also using a VERY small sample. To get a really accurate number, use a larger set of code (using multiple echo statements will be slower than a single echo...), and perform the operation many times (> 1000) and get an average.
  3. php.ini.... http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize http://www.php.net/manual/en/ini.core.php#ini.post-max-size
  4. MySQL will return the field name as "SUM(gplays)" when the sum operation is used, rather than just "gplays". Use the "AS" SQL command to give it a name: $q = "SELECT SUM('gplays') AS total_plays FROM " . Games . " "; $result = $database->query($q); // no need for the "die" here, there is error checking below /* check for errors */ if ( mysql_num_rows($result) != 1 ) { return 'Unable to get total plays'; } else { return mysql_result($result, 0, 'total_plays'); }
  5. Even though you are setting MAX_FILE_SIZE to something large enough for your file, php has two settings that will affect the maximum file size: upload_max_filesize and post_max_size. Both of these must also be set large enough to accommodate your file.
  6. file_get_contents is binary safe, so a zip file will not affect it.
  7. You'll have to close the php tag, and then reopen it... <?php $start = microtime_float(); ?> <table border="1"> <tr> ..... </table> <?php echo "Rendered in " . (microtime_float() - $start) . " seconds"; ?>
  8. Try it yourself. If it doesn't work, post your attempt and someone will help.
  9. file_get_contents reads the data into a variable (assuming the fopen wrappers are enabled). You can then save that data on your server.
  10. Change the order of your code.... <?php /* necessary for both operations */ $con = mysql_connect("localhost","peter","abc123") or die(mysql_error()); mysql_select_db("db", $con); /* was block 2, now block 1 */ $delete_person = $_POST['deletePerson']; foreach($delete_person as $id) { mysql_query("DELETE FROM person WHERE id='$id'"); } /* was block 1, now block 2 */ $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo ' <input type="checkbox" name="deletePerson[]" value="' . $row['id'] . '">' . $row['FirstName'] . $row['LastName'] . '<br /><br />'; } mysql_close($con); ?>
  11. If you are uploading the file, use the "'move_uploaded_file" command, rather than just "copy". There are some additional security checks performed. http://www.php.net/move_uploaded_file
  12. If you want to test it, use the microtime function.... <?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } ?><html> <head> <title></title> </head> <body> <?php $start = microtime_float(); echo '<table border="1">'; echo '<tr>'; echo '<th>Firstname</th>'; echo '<th>Lastname</th>'; echo '</tr>'; echo '<tr>'; echo '<td>Firstname</td>'; echo '<td>Lastname</td>'; echo '</tr>'; echo '</table>'; echo "Rendered in " . (microtime_float() - $start) . " seconds"; ?> </body> </html> Do the same for your other example.
  13. Use the file functions: http://www.php.net/file_get_contents and/or http://www.php.net/file http://www.php.net/fopen http://www.php.net/fread Or, if available, you could use cURL.
  14. Pass a comma separated list of valid usernames: isAuthorized("valid_user_1,valid_user_2,valid_user_3",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])
  15. Forgot about that. is_numeric is still a possibility, or you can cast as an int....or just use the regex.
  16. You are checking to see if the username is in an array of "valid" usernames: if (in_array($UserName, $arrUsers)) { $isValid = true; } However, the $arrUsers, which is generated here: $arrUsers = Explode(",", $strUsers); Will always be an empty array because you are not passing anything for it to create itself from: //The function expects the parameters as follows: function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) //you are passing the paramaters here: isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup']) So, you will always get a false result.
  17. Make sure you use "trim" on the user input first to eliminate any leading or trailing spaces. if (is_int($phone_number)) { echo "That phone number is " . strlen($phone_number) . " digits long!!"; } or if (preg_match('/^\d{10}$/', $phone_number)) { echo "That phone number is " . strlen($phone_number) . " digits long!!"; } PHP's weak typing is helpful here. You could also use "is_numeric" to test for the numberness of the value.
  18. Try one of these: http://www.phpclasses.org/browse/package/945.html http://www.phpclasses.org/browse/package/2322.html
  19. There are 10 digits in a US mobile number. There are two ways...you can force the user to conform to a certain format, e.g. ###-###-####, or you can accept all common formats and check for them, e.g.: (###) ###-####, ##########, ###-###-####, etc. With either one, the easiest way would probably be regex to check for format: $pattern = '/^\d{3}-\d{3}-\d{4}$/'; if (preg_match($pattern, trim($phone_number))) { /* Number matches format */ } else { /* Number does not match */ } Repeat ad nausem for other patterns. If using the first method, I would recommend using a JS frontend validation so that the user doesn't have to repeatedly resubmit the form if they make errors. With any method, do (re)validation on the backend. EDIT: There are 10 digits if you don't include the country code. If you do, then most US persons will only put "1 ###...", where as most Europeans will put either "+001..." or "001..." for a US country code.
  20. I would recommend using the example in the manual: http://www.php.net/features.file-upload Specifically, example two. That should get your file uploaded. To use a single file, do some thing like this: <?php if (count($_FILES) > 0) { /* code to handle file upload (see php manual) */ //pseudo code: if ($file_uploaded_successfully == true) { $message = "Your file has been uploaded"; } else { $message = "There was an error uploading the file"; } } ?> <!-- Put your html upload form here --> <?php echo $message; ?> Make sure that the form submits to the same page it's on. The premise is to check to see if the form was submitted ( "if (count($_FILES) > 0) ...' ), if it has, process the upload and set a message to display for the user.
  21. Put your text in a div, set the hight of the div to an absolute value, then set the overflow property to "auto". <div style="height: 25px; overflow: auto;"> a<br /> b<br /> c<br /> d<br /> e<br /> f<br /> g<br /> h<br /> i<br /> j<br /> k<br /> </div>
  22. use a ternary statement: <?php echo "Example Text... My name is" . ($name == "bob" ? "Charlie" : "") . ". Blah Blah?" ?> www.php.net/expressions
  23. What are you viewing the file with? If you are using notepad or a web browser, they won't show up...they're still there though. Notepad won't recognize just a "\n", but requires a "\r\n" to display a new line. If you are using a browser, remember that browsers ignore whitespace. You can either change it to "\r\n" to display correctly, or open using wordpad instead of notepad (or get a better text editor all together: notepad++, etc.).
  24. [code]Use parenthesis: [code] SELECT * FROM cmads WHERE addre='5' AND ( keyw LIKE '%$trimmed%' OR buzzname LIKE '%$trimmed%' OR descr LIKE '%$trimmed%' OR sub LIKE '%$trimmed%' ) ORDER BY keyw You will get dramatically different results depending on how you use them[/code][/code]
×
×
  • 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.