-
Posts
32 -
Joined
-
Last visited
Never
Everything posted by The Bat
-
Thanks for the help everyone, I'll go with Crayon's solution.
-
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?
-
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!
-
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
-
Hello, Is it possible to check if a function was called within a certain page? If so, how? Thanks.
-
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!
-
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.
-
Thanks for the help! btherl, your method works great but I have one question: what exactly are the ampersands do?
-
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!
-
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.
-
You should change the ereg function to eregi, otherwise someone can enter in an email address such as "[email protected]" and have it be invalid.
-
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).
-
The one that you use (in my opinion) is the best way, however the last .""; is not needed (of course keep the semicolon).
-
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?
-
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!
-
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.
-
Change $result = mysql_query($query); to: $result = mysql_query($query) or die (mysql_error()); and post the output.
-
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.
-
Quick Question On PHP Register and Login Scripts - MYSQL Error
The Bat replied to VeronMan's topic in PHP Coding Help
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. -
You just want to get the file name before the period? A simple $ext = explode('.', $filename); echo $ext[0]; should suffice.
-
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!
-
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.
-
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.
-
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").
-
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'.