Jump to content

nethnet

Members
  • Posts

    284
  • Joined

  • Last visited

Everything posted by nethnet

  1. Life has once again given me the opportunity to return to my passion of coding with PHP, and as such, I have found my way back home to these forums I'm excited to become involved here again, and hopefully I'll run into a lot of familiar faces along the way!
  2. Yes, you can use file handling functions as long as allow_url_fopen is enabled on your system.
  3. There are a few different ways to achieve this, each with their own pros and cons depending on what you want to do with the file. If you are just looking to grab the OUTPUT of the PHP script, I would recommend using fopen() to open the file, and then readfile() to load the output of the file into a variable. This, also, assumed that you have allow_url_fopen enabled on your system.
  4. Use the explode() function. <?php $string = "TOM||PAUL||HARRIS"; $array = explode("||", $string); echo $array[0]; // Echoes "TOM" ?>
  5. As Adam has said, you can only access the values of $row while you are within your loop.. trying to do so outside of that scope will produce null then the array is, at that point, null. You could try building a second array of just these "place" values that you obtain inside the loop, which will then persist outside of its scope.
  6. The time() function returns the current UNIX timestamp, which is the amount of seconds since the Unix Epoch (January 1st, 1970 0:00:00 GMT). The date() function formats a date in the way specified. As you have used, "w" will return the numerical representation of the day of the week. By default, the date() function uses the current date and time for the return value, so using date("w") and date("w", time()) will return the exact same thing. If, however, you wanted to know the day of the week exactly 100 days from now, you could use a combination of the two functions to do so: <?php $timestamp = time(); $onehundreddays = 60 * 60 * 24 * 100; // The amount of seconds in 100 days $finaltime = $timestamp + $onehundreddays; echo "In one hundred days, it will be " . date("l", $finaltime); ?> As you can see, UNIX timestamps become very useful when you want to manipulate dates or calculate spans of time between two dates. The second parameter of the date() function is entirely optional, and will default to the current timestamp, so putting the current value of time() in it is redundant and unnecessary. I hope that helps your understanding of these two functions.
  7. switch($_GET["b"]=="true") This is improper syntax, use this instead: switch($_GET['b'])
  8. Elaborate on this please. What do you mean exactly when you say you want to check a text box for an imbedded file? A text box will contain a string.. are you meaning to check for a filepath on your server?
  9. Give us a few lines of code above and below that, with line numbers, as well as the exact error messages again.
  10. I'm just going to take a stab in the dark here and say that what you want to do with the !empty() conditionals should use the boolean && instead. If you used the way you had, your conditional would evaluate to TRUE as long as ANY of those fields were not empty. It looks to me like a registration script of some kind, so the natural assumption is that you would only want the conditional to be TRUE as long as NONE of the fields were empty, in which case you would use && instead of ||.
  11. For the next link, change the if statement to this: if ($page < $total_pages) { The previous link shows on all pages of results, even page 1?
  12. Could you clarify what exactly you are trying to do? I mean, are you trying to implement a similar way of passing data in your own URLs like this, and then extract certain bits of it on your pages? Or are you literally taking a string that is a URL (abc.com) and trying to extract certain bits of information from it? Sorry if this seems like a stupid question, I'm just not entirely sure which of these you are trying to accomplish.
  13. Just change the OR to AND. This will return rows that match ALL of the criteria, instead of ANY of the criteria.
  14. Chances are if your server isn't allowing PHP files, it isn't allowing other technologies that would do this as well, such as CGI or ASP. You will have to check with your web host to see what kinds of files they allow.
  15. "public" is a keyword used in conjunction with class methods. Since these functions aren't part of a class, just get rid of the word "public" and it should work fine.
  16. You're not passing the letter and gender in your pagination links. After reading through your code, I've noticed some inconsistencies that look like you've added things and taken things away and it has kind of made the code a bit sloppy. I've cleaned the code up a bit and fixed the issue with the page links. Try this: <?php include("common.php"); for ($i = ord("A"); $i < ord("Z"); $i++) echo "<a href=\"alpha2.php?letter=" . chr($i) . "\">" . chr($i) . "</a> ¦ "; echo "<br>"; echo "<a href=\"?\">Show All</a></p><br /> <form method=\"post\" action=\"?\"> Select Gender :<br> Male:<input type=\"radio\" value=\"male\" name=\"gender\"><br> Female:<input type=\"radio\" value=\"female\" name=\"gender\"><br> <input type=\"hidden\" name=\"letter\" value=\"{$_GET['letter']}\" /> <input type=\"submit\" name=\"submit\" value=\"Search\" class=\"submit\" /> </form>"; mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); $page = (empty($_GET['page'])) ? 1 : $_GET['page']; $letter = (empty($_GET['letter'])) ? "%" : $_GET['letter']; $gender = (empty($_GET['gender'])) ? "%male" : $_GET['gender']; $max_results = 4; $from = (($page * $max_results) - $max_results); if(empty($_POST)) { $query = "SELECT * FROM `contacts` WHERE `fname` LIKE '".$letter."%' ORDER BY `fname` DESC LIMIT $from, $max_results"; } else { $gender = $_POST['gender']; $letter = $_POST['letter']; $query = "SELECT * FROM `contacts` WHERE `gender` LIKE '$gender' AND `fname` LIKE '$letter%' ORDER BY `fname` DESC LIMIT $from, $max_results"; } $result = mysql_query($query) or die(mysql_error()); $rows = mysql_num_rows($result); echo "<table border='1'>"; echo "<tr> <th>ID</th><th>Photo</th><th>Name</th><th>Gender</th></tr>"; if ($rows > 0) { while($row = mysql_fetch_array($result)) { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo '<a href="members_gallary.php?id='.$row['id']. '"><img src="rip_pages.php?id=' .$row['id'].'" height="35" width="45"></a>'; echo "</td><td>"; echo $row['fname']; echo "</td><td>"; echo $row['gender']; echo "</td></tr>"; } } else { echo "<tr><td colspan=\"4\">No results found!</td></tr>"; } echo "</table>"; echo "Total results = " . $rows; $total_pages = ceil($rows / $max_results); $letterstr = ($letter == "%") ? "" : "letter=" . $letter; $genderstr = ($gender == "%male") ? "" : "gender=" . $gender; echo "<p class=\"center\">Pages: "; if ($page > 1) { $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&$letterstr&$genderstr\">«</a> "; } for($i = 1; $i <= $total_pages; $i++) { if($page == $i) { echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&$letterstr&$genderstr\">$i</a> "; } } if($page < $rows){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&$letterstr&$genderstr\">»</a>"; } echo "</p>"; mysql_close(); ?> I also added a hidden field to your form to help the transition of data from POST (on the first page) to GET (on subsequent pages). Also, I didn't test this, so there may be a silly parse error somewhere. Just run it with error reporting turned on in case.
  17. Going back to your first script posted, I think it would work properly if you fixed these lines: $sex = $_POST['gender']; $query = "SELECT * FROM contacts WHERE gender = '$gender' AND fname LIKE '".$letter."%' ORDER BY fname DESC LIMIT $from, $max_results"; In here you set the gender from the form equal to the $sex variable, but then use the $gender variable to pull it from the database. You then use the $sex variable later in another query to the database. For ease of simplification, I would replace all three instances of $sex in your code with $gender. I didn't test this, and there may be other issues with the original code, but I spotted this and it seemed to be a likely cause of the issue you originally had.
  18. If you have a page, for example index.php, then just go to that file in your browser.. http://www.yoursite.com/index.php. If the browser prompts you for download, or if your code is displayed on the page as text, then you don't have PHP enabled. If you have a PHP script (not a blank PHP file) and when you access it you just see a blank page, chances are there is a parse or other fatal error in the code. Turn on error reporting to see what the error is. Add this to the top of your script: error_reporting(-1);
  19. Cron jobs could accomplish this if it needs to be executed precisely 15 minutes before the counter reaches 0. Although, if you just need to give the illusion that it is being executed 15 minutes prior, cron jobs would be an unnecessary complication. I worked on a project once where every player of the game was meant to be given a certain amount of resources every 30 minutes. Instead of using a cron job that ran exactly every 30 minutes, I just faked it by running a check every time a player loaded their account. It would check to see how long it has been since they last checked it, and give an appropriate amount of resources depending on the time. So if 2 hours had passed, it would give, at that moment, 4 times the amount of resources that players were meant to get every 30 minutes. This way, you give the illusion that it is being updated every 30 minutes, without actually having a cron job running. This is a very common practice in situations like this. Obviously, if it was absolutely necessary to do it spot on time, then this method wouldn't work for you.
  20. It means you are trying to treat one of your variables as an object when it isn't one. HTML frames are executed independently of each other; it's not the same as using include(), so to speak. Therefore, if you create an object in your parent script, and then try to call methods on that object in your frame, you will encounter an error like this (and vice versa).
  21. If you have access to your server root, you can recompile PHP with Zip support. The ZipArchive class is very useful for creating and managing dynamic Zip files. ZipArchive on the PHP Manual I didn't read through your code too closely, so it may be that your method is just as effective, just with a simple issue somewhere in the code, but I've used ZipArchive many times and have never occurred any issues. Good luck!
  22. Welcome to PHPFreaks! I learned all 4 of those technologies at the same time as well, so it can be done. Heck, throw in JavaScript for good measure and you'll be set
  23. Yes, people use methods like this all the time. This is accomplished by using the mod_rewrite Apache directive in conjunction with PHP's GET method. Basically, you tell Apache to interpret URLs differently, so that http://www.example.com/page22 in the browser will actually display http://www.example.com/index.php?param=page22. Here are some useful documents to read to get this working on your server: Apache's mod_rewrite documentation Article from PHPFreak's blog
  24. Sessions are unable to store certain object structures. To get around this, try to serialize() your object and then store that as the session, and then unserialize() it when you need to use it.
  25. If nothing is being output to the browser, chances are there is an error occurring that is causing the script to die. Try turning on error reporting to see what exactly the issue is. Just put this line of code at the top of your page: error_reporting(-1); @monkeytooth - I've used GoDaddy to host one of my dedicated servers for about 7 years and I've never encountered any issues with mail() or other PHP problems that extended beyond a malconfiguration on my part.
×
×
  • 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.