Jump to content

colombian

Members
  • Posts

    79
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

colombian's Achievements

Member

Member (2/5)

0

Reputation

  1. It is inside the class, and it is being used in that class, but somehow it is still complaining. I'll post the answer here at some point in the next few days. The real function names are descriptive - I've been doing PHP for a while, it's CAKE that was tripping me. Thanks for the responses.
  2. Well good to know, I thought I was going crazy. The function is basically that - however, it's inside a CAKEPHP application. I am just starting to get familiar with CAKEPHP, so there must be something going on that's preventing it from happening. I just tested it outside CAKE and it does work fine... If you know cake... It's inside a controller, I need two very similar functions, so I am using one function and passing the 1 parameter to both. The error is the normal: "Fatal error: call to undefined function....." and it specifies the line number where I am calling function a inside function b. No wonder why google wasn't of help, I'll go delve into CAKE - thanks again,
  3. I am stuck on something terribly simple, but Google isn't helping. How do I call a function inside another function in PHP5? It says the function is undefined. <?php function a() { echo "a"; } function b() { a(); } ?> When calling function b it says a is undefined. I was sure that all function scope was global. Thanks in advance.
  4. Many thanks... I feel very silly - I knew better than that, I started thinking too much, thinking it had something to do with the class. Anyhow - thanks a lot.
  5. I have this class, and with 2 columns and no implicit id, it works fine. However if the MySQL table has column that will by set to auto_increment. In procedural code, that ID is implied and you don't need to specify it in the SQL statement. However, I am getting an error with the class. Maybe the code will make it more clear: <?php class Name { public $Ages; public $Names; public function __construct ($name, $age) { $this->Ages = $age; $this->Names = $name; } public function add_name() { $query = "INSERT INTO name_age VALUES ('$this->Names', $this->Ages)"; $result = mysql_query($query); if (mysql_affected_rows() > 0) { echo "Success!"; } else { echo "<p> Failed</p>" . mysql_error() . "</p> <a href=\"staff.php\"> Return to main page </a>"; } } } $name1 = new Name('John', 28); $name1->add_name(); ?> The code works fine for a two column table with those values - but I am having trouble passing the auto_increment id column... Any help would be greatly appreciated. Thanks
  6. Additional question... I changed this to work with a constructor (just a sample), and it works just as intended - for a 2 column table. However, if I have an auto_num id column as the first one, it complains that the values do not match. My confusion is - typically in SQL queries you don't need to pass a value for the id auto_num column, but it is apparently asking for one - what should I do? Thank you. Code below: <?php class Name { public $Ages; public $Names; public function __construct ($name, $age) { $this->Ages = $age; $this->Names = $name; } public function add_name() { $query = "INSERT INTO name_age VALUES ('$this->Names', $this->Ages)"; $result = mysql_query($query); if (mysql_affected_rows() > 0) { echo "Success!"; } else { echo "<p> Failed</p>" . mysql_error() . "</p> <a href=\"staff.php\"> Return to main page </a>"; } } } $name1 = new Name('John', 28); $name1->add_name(); ?>
  7. Many thanks. This actually helps. I am not writing any large scale projects at the moment - but I want to be ready and learn OOP and start using it, even on small scale ones. Besides, I will likely start working on larger projects very soon. I will play around with this code to see what I can do - thanks again. I will use the constructor though, not sure why you didn't. I understand the use of the function inside the class better, many thanks for taking the time to show me that snippet.
  8. Below is an over-simplification of what I am trying to accomplish. I am having a hard time grasping some of this object oriented programming concepts. I want to know how to go from the class, to the insertion into MySQL. <?php class Stock { public $Symbol public $Price public function __construct ( $in_symbol $in_price ) { $this->Symbol = $in_symbol; $this->Price = $in_price; } } ?> I could just create the object with the data... So we have an html form letting the user pick the symbol and price. They click submit... How do I go from this to insert the data into MySQL OOP style? $stock1 = new Stock($in_pid, $in_price); Do I just insert it like typical procedural way? $sql = "INSERT INTO ... etc" If done this way, the class seems to be a waste, since it is not accomplishing anything. Any help would be appreciated. Thanks in advance.
  9. Security will be about the same - but some pointers: Don't be too specific about the error (you don't want to tell the hacker: "your script to read the security code is right, but you did X wrong" The sequence should be as follows: 1. Make sure the CAPTCHA runs first - and is successful. 2. If successful check the form information. 3. Validate email and content fields against spam attacks with either a regex or throwing an error on CC: BCC:, etc. 4. Now you can store/POST comments. Hope this helps.
  10. Thanks Blue, I believe SQL might not be enough - but hopefully you can shed some light on this: What if the names / addresses are slightly different? Like: John R. Smith, 600 pacificic ave, CA 98342 and John Rogers Smith, 600 SW Pacific AVE, CA 98342 Any ideas? Thanks again.
  11. How could I got about creating a script for deduping a mailing list? (Not email - just Name and address) I know this is broad, I just need some pointers and Google hasn't been helpful. The files can be obtained in CSV, Excel, among others (they can be converted from one to the other easily - so whichever format is easier to dedupe)
  12. Thank you! That did the trick - quick question though. Why does doing $html = (no .= ) cause it to break? More over, why does declaring $html before that loop cause it to break too? I had to declare $html up with the $hour array, and leave as is to make PHP happy. Just trying to understand what PHP is doing here. Thanks again.
  13. Here is my problem, I need this function to be part of a string of outputs. $output = "Html" //etc $output .= "select"; $output .= attending($total_people); However, it only returns 1 of the 9 supposed values for the select box. <?php function attending($var) { $hour = range(1,9); foreach ($hour as $h) { if($var == $h) { $selected = "selected"; } else { $selected = ""; } return "<option {$selected} value=\"{$h}\"> {$h} </option>"; } } ?> If I use "echo" instead of "return" it does give me all 9 outputs, but then I cannot make the form dynimically through the $output variable. Any help is appreciated. Thank you.
  14. You could do 2 things: 1. Integrate the 2 functions (the captcha and the form submission into 1 page). 2. Send your post information from your CAPTCHA the form processing. Integrating the 2 would make more sense, since the CAPTCHA is part of the form. Since the form is submitting for itself - I would place all the code from the for submission page into the else statement I mentioned above. There you would fill in all the $_POST variables to pass them only if the CAPTCHA is successful. So: ?php if ($_POST["submit"]) { if (!$resp->is_valid) { die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } // Would you not need an else here? else { //response is valid. maybe an elseif if you want. // HERE YOU INSERT THE CODE that was on the working form submission page. // Include the $_POST variables for the input. } } ?> Hope this helps.
  15. Well, this is probably Regex territory. You need to determine what particular things are html. Maybe there is a set of 4 that do that. for & and other misc html things like that you can try the htmlentities function. With regular expressions you can find a string with a <br> tag and change it to <br /> and any other things of that nature. On another note - while it is good to follow coding practices (W3C recommendations) you shouldn't worry too much about it - 99% of your users don't know, care, etc. (This comes from someone who uses XHTML 1.1 (strict))
×
×
  • 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.