silkfire
Members-
Posts
569 -
Joined
-
Last visited
Everything posted by silkfire
-
new to PHP - validating checkboxes in php - please help!!
silkfire replied to plaedien's topic in PHP Coding Help
Because your checkboxes are not related, you can give each checkbox a unique name. Remember, if a checkbox is UNCHECKED (not clicked) it will not post, so by using this knowledge you can check if a checkbox is checked or not. In your processing code, use statements like these: if (isset($_POST['police_check'])) // do something if checked Also I could see you named your form elements a bit unconventional. Use short lower case names, no spaces. Plus your checkboxes were never posted because they're outside the <form> tag. All form elements have to reside WITHIN the preferably same <form>!. The submit button does not need a name, by the way: First_name => first_name Surname => last_name Suburb => suburb Email_address => email Experience with child ages... => experience Availability => availability Phone_number => phone submit => REMOVE this name tag -
Use addslashes() function.
-
This depends on a few things. Do you always search for 2 rows at a time? Is it possible to separate date and time? I could think of using ORDER BY and LIMIT to achieve what you require.
-
Thank you man I solved it by storing the getcwd() during contructor of class then appending it to the file name during destruction. You were right, the file ended up in the root directory, really weird.
-
Mmmkay but I want this to be the last thing that is performed, I don't want the user to necessary call a ->finalize() function. Hmmmm....
-
I have a class and the last thing I want it to do is to generate a file with all the data. Unfortunately my write call never seems to run, are there any restrictions on this maybe? If I call file_put_contents somewhere else in the code it works as usual. function __destruct() { echo 'destruct'; // Called without problems file_put_contents('t.txt', 'eeee'); // NEVER PERFORMED, why?? } $b = new Class // doesn't matter its name file_put_contents('t.txt', 'eeee'); // Works perfectly
-
Help with multi-dimensional associative array
silkfire replied to arenaninja's topic in PHP Coding Help
Just use nested foreach loops then use an apporpriate sort function for the innermost loop. -
What PHP version you got?
-
You're asking how to build a tree from a parent / children array. This problem has been documented many times, here's a very good tutorial. try to use the non-recursive function for efficiency. http://www.tommylacroix.com/2008/09/10/php-design-pattern-building-a-tree/
-
1. As you see, SimpleXML XPath query returns you an array. In this case that array will always have one element, the SimpleXML object. SO you can do like this to retrieve a specific element: $element = array_pop($myDataObjects)->element; 2. You can echo out the XML of your node: $node->asXML();
-
You must not have searched for more than a minute. Here's a great guide: http://www.2basetechnologies.com/blog/2010/08/03/1-screen-scraping-with-xpath-in-php.html
-
sptrsn, who taught you to use HTML scraping with regex? Please use DOM with XPath it's so much faster and precise. Your query would be as simple as: //span[@id=TotalDue]
-
The formula for adding series starting from 1 to n is: n(n+1)/2. So for 4 it will be 4 * (4 + 1) / 2 = 20 / 2 = 10. Did that answer your question?
-
Why was "try" and "catch" introduced into PHP?
silkfire replied to marcbraulio's topic in PHP Coding Help
try / catch is a variant of the while loop. It means code execution should be broken if an Exception occurs. I guess it's more elegant to "take care" of the error instead of letting it occur by nature. -
I was more wondering if you could quickly filter out the base64 url strings to separate them from the rest and process the non-base64 first then the base64.
-
How do you know it's base64 url in the first place?
-
It's not double I just showed you in the paranthesis how the syntax goes. Use it like that =P
-
Make your two loops. In the inner loop, add all members to an array $members. Then use the awesome function array_chunk (array_chunk($members, 15)) that will split the array into equal parts of 15, leaving the last array with 15 or less members. Then run a foreach on this array and add all members to the text file.
-
Inte så svårt echo date('Y-m-d', strtotime($imap_date));
-
I searched online and seen some complex c and c# code which I didn't understand much of. But how do I generate an array with all string combinations based on length and from a charset? E.g. charset = {'a', 'b', 'c'} Length = 2. Then it should generate first all 1-char strings: a b c Then all 2-char strings: aa ab ac ba bb bc ca cb cc And then all added to the same array. I think there's some way of doing it with recursion but to me it's like thinking with a 4th dimension my mind can't grasp this logic!
-
Can you print_r $data after the foreach is finished?
-
How do the queries look there?
-
Ah that has nothing to so with your query, mate. Before performing operations you need to select the database that contains the tables. Like this: mysql_select_db('NAME OF DATABASE') I hope you know what the name is. Put this statemenet directly after the mysql_connect() statement.
-
Your form should be in HTML, no need to echo it out, even if you loop it. Plus you can hide your hidden field in the same cell as the text field. Multiple form fields are to have empty brackets [] at the end. <td style="text-align: center;"> <input type="hidden" name="item_id[]"> <input type="text" name="item_new_stock_total[]" style="width:20px" value="<?echo [$THE VALUE READ FROM DATABASE]?>"> </td> And in your processing page: require_once 'functions.php'; foreach ($_POST['item_new_stock_total'] as $key => $val) { $val = mysql_real_escape_string($val); $id = mysql_real_escape_string($_POST['item_id'][$key]); mysql_query("UPDATE items SET item_stock = '$val' WHERE item_id = '$id'"); }
-
1. Put an input hidden in your table that holds the id value so you can use it in your query later. 2. Escape your input data (even id) with mysql_real_escape. 3. Use "echo mysql_error()" function to show the error in your query.