Jump to content

Aeglos

Members
  • Posts

    87
  • Joined

  • Last visited

    Never

Everything posted by Aeglos

  1. I see now what you are attempting; getting the previous five integers. for ($x = $current-5; $x < $current; $x++) { if ($x < 1) { $x = 1; } echo $x; } That will give you the previous 5 integers before $current. Note the if() which is important if $current is lower than 5. Cheers.
  2. You are thinking all backwards. You want the values FROM one and UP TO your defined boundary, just do: for ($x = 1; $x < $current; $x++) { echo $x; } So you loop from 1 up to one less than your $current value (that's why you use '<' instead of '<='). That should output 123456 if $current is 7.
  3. The problem is that your supplied username/password is/are wrong.
  4. The single quotes around the $vegeid var are the problem. Somewhere the '15' gets converted to `15` which is column name designation. I'd try removing the single quotes around it (which works) or checking where and why they change... Maybe the sprintf function does it, don't really know. But since it's a value you generate and get yourself from the script/database, there should be no risks to removing the single quotes. May I ask why are you using sprintf to build the queries though? It's simplier to just concatenate the variables, seems like added bloat with no practical benefit to me.
  5. Yes, that is injected code. A little googling reveals that it's probably something uploaded through unsecured FTP access, or, a local virus that infects uploaded webpages. Change all of your access passwords, and everyone who has file access should check for virus. I think that includes the hosting service.
  6. I can't find a mistake at a quick glance. Could you put echo $insertSQL_b before the last mysql_query() and paste the output here? So we can check for errors in the full SQL query that you are trying to run.
  7. The "Notice: undefined index..." errors mean that those variables don't exist. It would seem that the form never set them and they were never posted, so check the form for errors. The error in your SQL syntax is due to the "NULL" you have in you column list. It servers no purpose and is messing things up. Notice that you have 11 values to insert, and 12 fields, that can't be... the quantity has to match, also SQL tries to map the first value to the NULL column which is nonexistant and the query fails. Remove the NULL item from the query. If you are concerned about an ID value in the database that comes first (as I asume), don't worry. If you don't reference columns in an insert query, SQL will fill them up with their default or simply leave them blank. Just remember to have the same number of values and (corresponding) column names in the query. ALSO. mysql_insert_id() will return nothing until you actually run the query, so you have to move it down... ... $result1 = mysql_query($insertSQL, $connection); $vegeId = mysql_insert_id(); // Here it will work, the query has already run. $insertSQL_b = ... //Your SQL query that uses $vegeId. $result2 = mysql_query($insertSQL_b, $connection);
  8. Seriously... did you even read or try to comprehend the error? It clearly states BLOB/TEXT types can't have default values... change: ITEM_DESCRIPTION TEXT DEFAULT '', to: ITEM_DESCRIPTION TEXT,
  9. mysql_query() can't accept 2 query strings. First argument is the query, second is the optional link identifier. You are basically saying "run $insertSQL query on the $insertSQL_b database connection". You have to use two different mysql_query() function calls, one with each query string. $result1 = mysql_query($insertSQL, $connect) or die(mysql_error()); $result2 = mysql_query($insertSQL_b, $connect) or die(mysql_error());
  10. Short PHP tags is a bad practice, use full <?php ?> always. It all comes down to this line: print('<a href="photos.php?cat_id='.$cat_id.'&pic_id='.$pic_id.'"><img src="images/'.$location.$file_name.'" width="100" border="0"></a>'); Check for $pic_id > 0 before that line, if the condition is false, execute above said line, else skip it. If you want cleaner code (or at least more organized) try a mini front controller aproach... Before doing anything check all the GET vars. If $pic_id is PROPERLY set you know you only have to display a single image. If it is not set then check for a properly set $cat_id and display the thumbnails, or else just display the categories. The usual simple way is with an $action variable, like $action=thumbnails&cat_id=3 or $action=display&pic_id=76. Then you only check for the proper action (with an if-ifelse-else or a switch() conditional) and act accordingly using the rest of the GET variables supplied. Keeps things more organized. After that a whole world opens up which leads to full front controllers, page controllers, mvc and whatnot. Cheers.
  11. I don't see the POST variable "dob" set anywhere, you have three distinct variables dob_DD, dob_MM and dob_YYYY (Through PHP generated forms I assume...) but no plain 'dob' anywhere in the form. So I assume your "DOB" column is empty for all users in the database and you are searching for an empty date on an empty column wich evaluates to true always. Also, the HTTP_VARS_* arrays are horribly deprecated, you should use $_POST, $_GET and similar arrays instead. You should also try not to skip braces in the if conditional blocks, it makes the code harder to understand and leads to errors. And finally, using globals (i.e. global $sErr) is a very bad practice unless you really know what you are doing. Cheers.
  12. The script is working as intended, you have to realize that converting foot/inches height into decimals does not work that well. 5'11" to decimal is 5.11 which is clearly lower than 5.5 and higher than 5.0 Possible solutions would be creating two separate columns in the DB, one for feet and one for inches and sort by feet then inches. Or a more ugly approach is check if the $in variable is less than 10, and in that case divide it by 1000 rather than by 100. Not too sure about that though... You'd have to re-format them again when displaying them.
  13. It will work as long as $error_text[$error_display[0]] is a numeric value... I think you are confusing array keys with array values. Does $error_display[0] hold a numeric value? or the error text?.
  14. Try changing the format of all the cookie values, from this: $userValue = "$result[username]"; to this: $userValue = $result['username'];
  15. 733407 is the number of days. Convert it to the current number of seconds and then use strftime(); <?php $time = 733407*24*60*60; $date = strftime("%Y-%m-%d", $time); echo $date; //Should output YYYY-MM-DD ?>
  16. The value you pass to the function argument replaces that variable inside the function scope. The defined function argument variable name does not need to be the same as the one you pass to it. <?php function abc($var) { return $var+5; } $num = 7; $var = 9; echo abc(4); //returns 9 echo abc($num); //returns 12 echo abc($var); //returns 14 ?> They all work. Now, for multiple arguments, they get replaced in order and by name. <?php function abc($var1, $var2, $var3) { return 5 + $var1 + $var2 + $var3; } $num1 = 2 $num2 = 3 $num3 = 4 $var5 = 1 $goo = 4 $puppy = 7 echo abc(1,2,3); //inside the function, $var1=1, $var2=2, $var3=3, so, 5+1+2+3 = 11 echo abc($num1, $num2, $num3); // now $var1=$num1, $var2=$num2, $var3=$num3, so 5+2+3+4 = 14 echo abc($num2, $num3, $num1); // now $var1=$num2, $var2=$num3, $var3=$num1, so 5+3+4+2 = 14 echo abc($puppy, $num2, $goo); // now $var1=$puppy, $var2=$num2, $var3=$goo, so 5+7+3+4 = 19 echo abc($var5, $var5, $var5); // now $var1, $var2 and $var3 all are equal to $var5, so 5+1+1+1 = 8 ?> Notice a few things: For numeric operations there are no double quotes. You are using string operations in your functions... you would print "5+2+3+4" instead of the total result. Also, you are echoing the values twice, once inside the function and once outside when you call it. And finally, you can't return multiple values, as in: return $var1,$var2,$var3. To do something like that you have to set the variables inside an array or list and then return that array or list. Cheers.
  17. Did you even try to debug it yourself? You have a semicolon inside your dbConnect() arguments. Also your $disconnect variable breaks the function since you close the connection before selecting a database or running any query, which makes no sense. Also, the global keyword is evil. Try to stay away from it.
  18. Try native PHP. template.php <?php foreach($cats as $main_category => $sub_cats): ?> <h1><?php echo $main_category ?></h1> <ul> <?php foreach($sub_cats as $category): ?> <li><?php echo $category?></li> <?php endforeach; ?> </ul> <?php endforeach; ?> Then you just supply template.php with the data arrays, something like, script.php <?php $cats = array(); $sql = mysql_query("SELECT * FROM categories"); while ($row = mysql_fetch_assoc($sql)) { $sql2 = mysql_query("SELECT * FROM categories2 WHERE cat_id='" . $row['id'] . "'"); $subs = mysql_fetch_assoc($sql2); $cats[$row['name']] = $subs; } give_array_data_to_template($cats, $template_file); ?> Do note that your queries can be greatly improved by using JOIN on cat_id for the second table. It will reduce the script to just one database query and organize the resulting array in a much more accesible form. I suggest that you take a look at that (JOINs) first. If you do not want to use native PHP in your templates, you will need to code some sort of parsing engine for loops and control structures, which I personally don't recommend. PHP has everything you need for templates already. Cheers.
  19. You are missing mutiple semicolons at the end your statements.
  20. A yes, I see now how the dynamic list is done, I hadn't noticed the .= in the box method. My inquiry about the database call still stands though. What if you need to manipulate database results before displaying them? Like changing from timestamp to date format, or adding different columns into one?
  21. If I may ask, why is it a singleton? As I see, it severly limits the class flexibility... for example, what happens if I have to parse two templates before outputting anything which hold similar placeholder names? The values will get overwritten and the first template will be lost. Displaying two consecutive users list divided by group for example. Same template and placeholders, different values, same instance -> one is lost. Which brings me to the second question: What happens when there is a template with a dynamic sized list? The registered users for example, the way your class is set, I would have to enter hundreds of <DATA:> lables in the template instead of having a way to define dynamic loops. (Or else I misunderstood your methods, I'm sleepy...) What if I need a template inside a template inside a template? And last but not least; why is the template class accesing directly de database object for results? This couples your template with unrelated parts of your application. Objects should have a sinlge responsability and clear dependencies. Right now it has at least two responsabilities: Presenting data and fetching the data. The dependency on the DATABASE class is also not transparent in the class API as it depends on a specific named class and implementation which can't be seen or isn't implied from the outside. If it must use the database class, consider using a setter, passing it as an argument in the constructor, dependency injection or a registry. (On the record, I despise singletons... but others love them so this argument is somewhat biased). Anyway, I would advocate in favor of a data setter somewhere which recieves the database object output or whichever data is needed and stores it inside the class for later use. Cheers.
  22. Kohana does this effortlesly. Just have your controllers extend the Template_Controller and specify a master template in the constructor, and voilá. On top of that, Kohana's "Views within views" I find brilliant, where you can do this: $page = new View('views/site'); $page->title = 'Test page with lunch menu'; $page->content = new View('views/lunch_menu'); $page->render; It's so absurdly simple and so blatantly obvious it makes really ashamed to never have thought of it... makes me realize how much I still have to learn about OOP
  23. Kohana: kohanaphp.com PHP5+ only, full OOP, light, modular, excellent ORM, uses a more traditional MVC approach. The only drawbacks I see are the documentation which is still a bit lacking (but being improved upon) and that it's still relatively new and not widely known. It was originally a community created fork of Code Igniter, made due to the lack of updates on CI some time ago.
  24. You know, that looks surprisingly similar (though far less complex) to the core Kohana framework event system. I just recently discovered that framework which turned out to be a rather young PHP5 full OOP community fork of Code Igniter. Though it's recently new, what I've seen in the code far surpasses that of CI in my book by all means. If you haven't, take a look: click gently. Particularly, as I said, to the event system that drives the FW. I'm currently seeing how I can adapt something similar to my FW. On a personal note, I've tampered with something similar before in my FW using a chain of command which includes the ActionController's relevant called method in the chain, so I can load/unload and do things before and after the main page execution (afterLoad, afterRender). Sorta like intercepting filters. Though that idea works, it has some minor quirks that made me put it on hold, mainly because it mixed top level procedures (Auth, ACL, environment filtering) with more particular request calls such as Contact Forms in the template . I'm now more inclined to move everything to an event system with an observer approach instead of a command chain.
  25. Form variables don't just automagically apear by id name in your code, they are all wrapped inside the $_POST array, which you have referenced nowhere, that's why all your variables are empty. Also you are still inmediatly overwritting your SELECT statement with your UPDATE statement, effectively making the SELECT by account and password completely useless.
×
×
  • 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.