
Bramme
Members-
Posts
37 -
Joined
-
Last visited
Never
Everything posted by Bramme
-
hmm, i totally forgot about htis topic. the problem has been solved... I rewrote a part of the class indeed, but also changed the order of which fucntions i'm calling in index.php, i think the problem might've been there.... dunno for sure though. Anyway, it's solved. thanks for the info though!
-
[SOLVED] Check database for fully booked session before submitting
Bramme replied to biggieuk's topic in PHP Coding Help
basic idea: confirmation.php if(isset($_POST['Submit'])) { $capacity = get the value, either from your form or your database; $placesbooked = get the value, either from your form or your database; if($capacity - $placesbooked < 0) { echo 'error!'; } else { //store the values from your form temporarily in a session (don't forget to start it!) $_SESSION['value'] = $_POST['value']; header("Location: confirm.php"); } confirm.php echo '<p>Your trip is succesfully booked</p>'; echo '<p>Your details were: <ul>'; echo '<li>'.$_SESSION['value'].'</li>'; echo '</ul>'; etc -
indeed, i'd do it with php too... when the user click the submit button, run a script that checks if it's a valid email address, then add it to a database, and then create a second form (that only you can access), with the necessary things for your email, next, loop through your database with emails and send that mail to everyone... Might get a little slow though if you have a lot of subscribers...
-
I've got a multidimensional associative array that looks like this: Array ( [cont] => Array ( [filename] => /var/www/vhosts/bramme.net/subdomains/dev/httpdocs/admin/modules/content.php [name] => 2-Content [subnav] => Add, Edit, Delete pages [dependent] => 3-Navigation ) [dashboard] => Array ( [filename] => /var/www/vhosts/bramme.net/subdomains/dev/httpdocs/admin/modules/dashboard.php [name] => 1-Dashboard [subnav] => [dependent] => ) [nav] => Array ( [filename] => /var/www/vhosts/bramme.net/subdomains/dev/httpdocs/admin/modules/navigation.php [name] => 3-Navigation [subnav] => Edit [dependent] => 2-Content ) ) A function reads a set directory and builds that array, as you can see, some files need another, indicated with the dependent file's name. Now I need to check for each array key (cont, dashboard, nav) if their dependent value (if any) matches any of the name values, thus being sure the dependent file is existent too. Instead of building a new piece of code that loops through my directory again, I thought I could just do it with !in_array, like this foreach($this->modules as $module) { if(!empty($module['dependent'])) { $dep = $module['dependent']; if(!in_array($dep, $this->modules[]['name'])) { die("Dependent file not present"); } } } but it's clearly not working. Anyone suggestions on how to do this?
-
I don't need a line specific correction here, I just need some pointers to know where to look at... Did I probably forget to mention a $this-> somewhere, could it be a typo or is it some php setting... I'm completely at a loss here, I don't know where to look at.
-
lol@"a plant" But yeah, some basic php, mysql and OO PHP should cover it... unless you'd want flash animations too...
-
Example of what's happening: class MyClass { private $items = array(); function dostuffwithitems() { do stuff; return $this->items; } function dosmthelse() { print_r($this->items); } } I did the print_r to test because my second function wasn't working, and it just echo'ed array( )... It's still empty, if I change the private var to 'boo', it prints 'boo' instead of the array I built with the first function... I've tried it with other variables too, nothing prints correctly or returns like it should... Anyone can tell me what I'm doing wrong? Full code here: http://dev.bramme.net/files/Modular.class.phps
-
ob_start; workaround?
-
are you sure the path is correct? else try with <?php $root = $_SERVER['DOCUMENT_ROOT']; $path= $root.'/uploads/'; $i = count(glob($path.'*')); echo $i; ?>
-
yes indeed. it would be much easier to extend your existing users table like this as it is now (i'm guessing) user_id | name | password as it should be user_id | name | password | a | field | for | everything | you | want | to | save. And then in your code when the user has entered the correct login and password, you should add smth like $_SESSION['userid'] = $id (where $id could be fetched from the database). Next, you redirect them all to the same page which has a table like <?php $userid = $_SESSION['userid']; $userdata = mysql_fetch_assoc(mysql_query("SELECT * FROM users WHERE user_id = $userid)); echo "<ul>\n<li>Name: $userdata['name']</li>\n<li>Field: $userdata['field']</li>\n</ul>"; ?> Something like that...
-
Okay, I'm building my own little CMS for later use, meanwhile experimenting a little with classes etc. I have a folder which contains "module" files, each file will have specific functionalities, like a file content.php to edit the content of the site, a blog.php to edit a blog etc. Now I'm writing a function that reads those files from their directory and checks the file for certain strings: a php comment that indicates it's an actual module file and then 3 xml-like tags that define the name of the module, an abbreviation to use in the url's and what items it should list in a subnav. For example, content.php looks like this: <?php /* Modular Module */ /** Properties <cat>content</cat> <name>Content</name> <subnav>'Add, Edit, Delete page'</subnav> */ ..... my php functions work like this: $k = 0; while (false !== ($file = readdir($handle))) { $modContent = file_get_contents($this->modulesDir.$file); if($this->EvalFile($file)) { if($this->isModule($modContent)) { $this->modules[$k]['filename'] = $file; $this->modules[$k]['name'] = $this->GetModuleProperty($modContent, 'name'); $this->modules[$k]['navcat'] = $this->GetModuleProperty($modContent, 'cat'); $this->modules[$k]['subnav'] = $this->GetModuleProperty($modContent, 'subnav'); } } $k++; } The getmodule property is the one that goes looking for what's between the tags: private function GetModuleProperty ($content, $tag) { $startTag = '<'.$tag.'>'; $endTag = '</'.$tag.'>'; $start = strpos($content, $startTag) + strlen($startTag); $length = strpos($content, $endTag) - $start; $property = substr($content, $start, $length); return $property; } Full class file if needed Now this is working perfectly for the name and subnav tags, but for some odd reason it won't work with the cat tags. I've renamed, changed what's in them... If I print_r($modules) i get this: See online example. Also, could anyone tell me why the indexes (defined by $k) of my array are 1 and 3 instead of 0 and 1. There's only 2 files in the directory, but it's as if the code checks each file once (adding 1 to $k) and when it checks a second time it adds it to the array...
-
Okay, this is not really a technical question, but more an issue of semantics (I think). I've been messing around with OO PHP for a few days now, starting a little home brewn application, extending Smarty. Now I've read OO PHP: Concepts, Techniques and Code, which helped me a lot, but I still have a question: Before you build any functions in your class, you declare your variables. Now, which variables should I declare? All of them I'll use in my Class, even though they're only used in one function, or should I rather only declare the one that will be used in multiple functions. I'm guessing it's the second one, but the book's not entirely clear on the item. Also, apparently, you can't declare a class variable using another variable?
-
|| die("blah") had to be deleted.
-
thanks a bunch, that was stupid of me. Also, $file = opendir(path) !== false had to be changed into false !== ($file = opendir(path))
-
well, it's an image... a bunch of pixels that define forms and color and stuff. It's not a string, nor an array... So you can't read it with php. The only computerprograms who can "read" (meaning look at the image and interpret the text, meaning transforming it into a string) images are OCR thingies... I'm afraid your users will have to keep adding things manually.
-
Could anybody tell me why this code isn't working: <?php //admin/index.php define('ROOT', $_SERVER['DOCUMENT_ROOT']); require(ROOT.'/libs/Modular.class.php'); $core = new Modular(); $core->template_dir = ROOT.'/admin/templates'; $core->compile_dir = ROOT.'/admin/templates_c'; $uModules = array(); if ($handle = opendir(ROOT.'/admin/mods/') || die("Could not open Modules directory")) { while ($file = readdir($handle) !== false) { if($file != "." && $file != ".." && !is_dir(ROOT.'/admin/mods/'.$file)) { $Module = fopen(ROOT.'/admin/mods/'.$file, 'r'); $modContent = fread($Module, 26); fclose($Module); $uModules[] = $file; } } closedir($handle); } $core->assign('uModules', $uModules); $core->display('index.tpl'); ?> I get two warnings: Warning: readdir(): supplied argument is not a valid Directory resource in /path/index.php on line 14 Warning: closedir(): supplied argument is not a valid Directory resource in /path/index.php on line 25 Line 14 and 25 being the only ones with readdir and closedir in them...
-
I must say, I've enjoyed Object-Oriented PHP: Concepts, Techniques and Code a lot. It's really well written and uses an approach I like better then the "compare a class to a dog, it barks, jumps etc..."
-
Okay, this is bugging me. I've written a small class, extending Smarty and I want to go through a folder, checking the files in it. Now I wrote the code first in line, to see if it worked and then converted it to a function in my class (seeing as I'm kinda new to OO and I was merely experimenting). Now I'm getting two warnings, resulting in my script actually not working: Warning: readdir(): supplied argument is not a valid Directory resource Warning: closedir(): supplied argument is not a valid Directory resource Here's my code. <?php require(ROOT.'/libs/Smarty.class.php'); class Modular extends Smarty { var $modulesDir = null; var $uModules = array(); //Construct function, starting Smarty public function __construct() { $this->modulesDir = ROOT.'/admin/mods/'; $this->config_dir = ROOT.'/libs/configs/'; } public function getModules() { if ($handle = opendir($this->modulesDir) || die("Could not open Modules directory")) { while ($file = readdir($handle) !== false) { if($file != "." && $file != ".." && !is_dir($this->modulesDir.$file)) { $Module = fopen($this->modulesDir.$file, 'r'); $modContent = fread($Module, 26); fclose($Module); $this->uModules[] = $file; } } closedir($handle); } return $this->uModules; } /* end class */} ?> First I thought it had something to do with safemode being on, but my host turned it off and it hasn't changed... Damn, i changed it back to how i started off, putting the code directly into index.php, not using a function, but the problem persists. Posting in the general php help area too...
-
sorry for bumping, but i'm really stuffed with this problem... anyone an idea?
-
[SOLVED] what is the difference in these lines ?
Bramme replied to myharshdesigner's topic in PHP Coding Help
the second one is used when uploading files...