-
Posts
15,227 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
foreach($xml->one as $one) { foreach($one->array->arra1 as $arra1) { // ... } }
-
I vaguely remember a way that you could catch one/some of those, in some special circumstance probably under your control. Of course I don't remember how.
-
What exec?
-
That would trigger a parse error as soon as the file is loaded. I don't remember for sure but you might be able to trap the error with set_error_handler() and interrupt the script however you see fit (such as by throwing an exception). Maybe. If not then you'd have to run the file through php -l and look for complaints. Or you could just let the error happen. It's a parse error after all. It should never, ever happen in real code.
-
No. Very no.
-
It's GET, not POST. Does that explain it?
-
Bypassing Passing MYSQLI object into functions
requinix replied to Arnsenal's topic in PHP Coding Help
What you're thinking of is global variables and they are almost always the wrong thing to use. Better would be to use a class to get the object, like class DB { private static $mysqli = null; public static function get() { if (!self::$mysqli) { self::$mysqli = // new mysqli } return self::$mysqli; } } $db = DB::get(); -
Case matters. Do you perhaps want it to find "replaced" too?
-
Considering the generic terms "filter" and "results", I'll just say you should probably use a loop. Or two.
-
Separate INSERTs for what? Answers? If you don't have too many at once you can do a batch INSERT, but yeah that's how you'd do it.
-
Or the simpler, non-lookaround version of just Replaced (\w+)
-
Instead of them calling themselves for the loop, make them call each other. Then only start the one you want to run first.
-
You have two different ways of coming up with activities (counting nodes versus a search on //activity), which isn't all that surprising since you're using two different XML files. What's up with that? [edit] And what does any of this have to do with "display image instead of image file name"?
-
Depends on the size of the array and where it's coming from. But in general you can WHERE field IN ("value 1", "value 2", "value 3") or WHERE (field = "value1" OR field = "value 2" OR field = "value 3")
-
Yeah: a table listing pages/forms, a table listing questions per form, and a table listing answers per user per question. You might want to add a "question type" for, at the very least, a difference between a single-line answer and a multi-line answer, but of course that's totally dependent on the app.
-
Arrays The answer is in there.
-
The first Rule will also match that second URL you're trying. Stick in an [R] in both Rules to see where you're being redirected to. And switch them around so they're in order of decreasing specificity: the cart/ one first, the catch-all last.
-
If you have a fairly small number of privileges and know that it can't expand at runtime then bitwise is definitely the easiest solution (though there might be a bit of a learning curve first). Otherwise it's a pain and it's easier managed as a "normal" set of key/value pairs stored somewhere.
-
Obligatory "whose website and are they allowing you to do this?"
-
How to delete file by disregarding the file extention?
requinix replied to bugzy's topic in PHP Coding Help
Use glob to grab all the files matching the duck.* pattern and delete each one. -
Use them in any way that treats the values as strings. Like with echo, or strval(), or a typecast to string, or interpolated in a string, or most of the str*() functions, or lots of other ways.
-
copy move_uploaded_file move_uploaded_file() is safer and actually moves the file.
-
1. Uppercase $_POST. Variables are case-sensitive. 2. $target_path has to include the filename. 3. $_FILES[...]["type"] cannot be trusted. Use getimagesize to determine if the file is an image. 4. Your logic is a bit wrong. 5. You also need to check for other error codes. At the very least do an ==UPLOAD_ERR_OK. 6. Make sure your filename is safe. Has the right extension according to the type of image. Again, can't trust the $_FILES[...]["name"] to have the right extension - you need to set it yourself.
-
Is it ok to put an insert statement inside a foreach?
requinix replied to bugzy's topic in PHP Coding Help
Besides the INSERT and mysql_insert_id() you've got a larger problem: what you're doing with $cat_get_ins is not safe. Ironically it's the one thing you didn't ask about. Stuff in $_POST, $_GET, ($_REQUEST,) and $_COOKIE come from the user and should never be used directly in anything without validating and/or sanitizing it first. For example, you may think $_POST['item_cat'] is an array of integers but that's not necessarily true. It may be a single text field. Yeah sure, your form says one thing, but there's no way to make sure that the form wasn't tampered with before it was submitted to you. Blah blah blah SQL injection and XSS. $_POST['item_cat'] = (array)$_POST['item_cat']; foreach($_POST['item_cat'] as $cat_get_ins) { $cat_get_ins = (int)$cat_get_ins; // ... } -
First, a SELECT * will grab everything from every table referenced. Do you want all the information from the images and pages and img_assigned tables? Probably not. To deal with the duplication you can do one of two things: 1. Use a second query. First one gets the page data, second one gets the images. 2. Select just the information you want from the pages and images table, grab the first row and use it to determine the page data, then use your loop to get the image data.