Jump to content

The Bat

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Everything posted by The Bat

  1. Thanks for the help everyone, I'll go with Crayon's solution.
  2. Hi everyone, my PHP skills are a bit rusty, so... I'm using basename($_SERVER['PHP_SELF']) to get (for example) blahblah_blah_stuff.php. What would be the best way to extract just the word "stuff" (the word right before ".php" and right after the last underscore) from it?
  3. Hello, I find myself using quite a bit of (example): function say_greeting($greeting = null) { $greeting = ($greeting) ? $greeting : 'Hello!' echo $greeting; } in my code (return $greeting if set, otherwise return 'Hello!'), and it's certainly not very DRY. In Ruby, a simple: def say_greeting(greeting = nil) print greeting || 'Hello!' end does the trick. I'm wondering if I can do something similar in PHP instead of what I am doing? Thanks!
  4. If I understand what you're talking about (fetching records from a table), then I think this is what you want... $query = mysql_query("SELECT * FROM stuff ORDER BY 'id'"); while ($row = mysql_fetch_array($query)) { echo $row['column_name']; echo $row['different_column_name']; # etc... } Much easier
  5. Hello, Is it possible to check if a function was called within a certain page? If so, how? Thanks.
  6. I have an .htaccess file which contains RewriteRule and RewriteCond statements. Here is the code (snippets are examples): RewriteCond %{REQUEST_URI} /cat [OR] RewriteRule ^([^/\.]*)/?$ cat.php?kitty=$1 [L] That way when the URL is mysite.com/cat/foo, foo is kitty. The problem is that "kitty" is applied to all pages. I tried adding RewriteCond %{REQUEST_URI} !(/cat) [OR] RewriteRule ^([^/\.]*)/?$ index.php?something=$1 [L] So that if the URL does not end with /cat, "kitty" will be "something". But this does not work. How can I fix this? Thank you!
  7. Of course you could also use getimagesize() in an if statement, and not have the upload continue if the size is not within your desired range.
  8. Thanks for the help! btherl, your method works great but I have one question: what exactly are the ampersands do?
  9. Hello, Is it at all possible in PHP to have "flexible" functions? For example, there's a function which has 3 parameters, and I only want to utilize 2 - the first one and last one. Instead of typing myFunc('first', false, 'third'); Could I/how would I do this? myFunc('first', $thirdparam = 'third'); (Assuming $thirdparam is the same variable used to declare the third parameter when creating the function.) Using Rails has had me wanting this functionality in PHP Thanks for the help!
  10. Not necessarily. If you use a RDMS, and you only need to call rows with a certain condition (like this) mysql_query("SELECT * FROM mytable WHERE myfield = 'something'"); and if it returns, say, 3 rows - that will take no time at all. However, when using a flat file, you'd need to load the whole file first before calling whatever information. Plus, it is extremely easy to work with MySQL in PHP.
  11. You should change the ereg function to eregi, otherwise someone can enter in an email address such as "JoeSmith@blah.com" and have it be invalid.
  12. On every page you want to restrict, you can put <?php if (!isset($_SESSION['sessionname']) { header('location: index.php'); } ?> at the very top of the page. If there is no session, it redirects to index.php (you can also change index.php to whatever you want, like a page saying they were trying to access a restricted section of the site).
  13. The one that you use (in my opinion) is the best way, however the last .""; is not needed (of course keep the semicolon).
  14. Thank you, however it still does not work. But if I replace it with the following (for testing purposes): function buttonDown(obj) { obj.style.visibility = 'hidden'; } It works fine. Why is this?
  15. Hello, I'm not that good in JavaScript, so bare with me. In an external JS file, I have the following function: function buttonDown(obj) { obj.style.backgroundImage = 'url(\'images/button-down.png\')'; } And then I have an onClick attribute applied to a div: <a onclick="buttonDown(this)"><div id="button"></a> This isn't working for some reason... but when I put the function code into the onClick attribute itself, it does work. Thank you for your help!
  16. Someone posted a comment saying "[..] but your attitude not to close td and tr tags drives me crazy " and the video poster replied "lol, thanks, yeah, I am not that strict on ending tags". That right there is a huge hint not follow any of his techniques. And he sounds 13 ._. Thank you, thorpe, for that link! I have not known about until now. Very good resource. P.S.: My squal.
  17. Change $result = mysql_query($query); to: $result = mysql_query($query) or die (mysql_error()); and post the output.
  18. Hey there, I know how to authenticate users and all that (get matches from a database, if there's a match set a cookie, etc. etc.), but I'm wondering if there's a better, more secure way to validate a user other than a cookie. Currently, the best way I know how to validate someone is to store someone's username in a cookie, and get their info by the SQL statement below: mysql_query("SELECT * FROM users WHERE username='".$_COOKIE['username']."'); Which, I can assume is not that secure. Yes, I know all about sessions, and I would much rather use them, but the only thing not wanting me to is the abililty (or lack thereof) for sessions to expire at the time I specify (for example when a user clicks 'Remember Me' during login). Or do I just not know about session expire time? I've heard of someone saying to store the cookie contents into a session, and just use all the sessions in the queries and what not, but can't a user just edit the cookie value thus making a session the same value? (A user can edit cookie values, right?) I'm looking forward to all of your information, and thanks for the help.
  19. Just curious, how do you know PHP but not even the basics of MySQL/SQL? Read the MySQL docs and/or use a database management system such as phpMyAdmin.
  20. You just want to get the file name before the period? A simple $ext = explode('.', $filename); echo $ext[0]; should suffice.
  21. Hmm, I copied your code and modified it to work on my webserver. First, I gave the submit button a name, and then added an if statement around move_uploaded_file so that it only tries to upload when the submit button is clicked. Also, did you chmod your images folder to 777? Here is the new code: <form action="upload.php" method = "post" enctype = "multipart/form-data"> Photographer name: <input type="text" name="authorname" size="40" /> Upload File: <input type="file" name="filename" id = "filename" size="40" /> File Type: <select name = "select"> <option value = "JPEG">JPEG</option> <option value = "GIF">GIF</option> <option value = "PNG">PNG</option> <option value = "other">Other</option> </select> Photo Name: <input type = "text" name = "photoname" /> Photo Description: <input type = "text" name = "photodescription" /> <input name="submit" type="submit" value = "submit"/> <input type="reset" value = "reset"/> </form> <?php include("connect.php"); $path = "/images/"; $authname = $_POST['authorname']; $phototype = $_POST['select']; $photoitself = $_POST['filename']; $photoname = $_POST['photoname']; $photodesc = $_POST['photodescription']; if ($_POST['submit']) { if (move_uploaded_file($_FILES['filename']['tmp_name'], $path.$_FILES['filename']['name'])) { echo 'Image uploaded!'; } else { echo 'Sorry, your image wasn\'t uploaded. Upload error: '.$_FILES['filename']['error']; } } ?> That should do it for you. Good luck!
  22. It seems like you're nesting 2 of the same things ($result), and could be better typed like this: <?php if ($result = mysql_query("SELECT username,password FROM login WHERE username = '$emailID' and userpassword='$password'")) { $flag = 1; } else { $flag = 0; } ?> Try that, and see how it works.
  23. You should change this line: move_uploaded_file($files['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name']); to: move_uploaded_file($_FILES['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name']); If that doesn't help, you could change the above to: if (move_uploaded_file($_FILES['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name'])) { echo 'Image uploaded!'; } else { echo 'Error: '.$_FILES['filename']['error']; } And then look up the error code here: http://us3.php.net/manual/en/features.file-upload.errors.php Also, is addphoto3.php the PHP code you posted? If so, then you should remove '/public_html/' from the above line.
  24. In the first table you mentioned, you could put a field titled 'comment_id', which maches the id in the second table, then use a WHERE clause in your SQL when showing your comments (ie: "WHERE comment_id=X").
  25. The random characters in the session is the encrypted value of it. To display the un-encrypted value, just do <?php echo $_SESSION['name']; ?> So if $name was, for instance, 'Andrew', then the above code would display 'Andrew'.
×
×
  • 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.