php5

Database Error Handling: What if You have to Call Outside service and the Transaction Fails?

We all know that we can always wrap our database call in transaction ( with or without a proper ORM), in a form like this: $con = Propel::getConnection(EventPeer::DATABASE_NAME); try { $con->begin(); // do your update, save, delete or whatever here. $con->commit(); } catch (PropelException $e) { $con->rollback(); thr...

PHP Error: Function name must be a string.

I added following few lines on top of my PHP code, but it is giving error: Fatal error: Function name must be a string in /home/reg.php on line 2 <?php if ($_COOKIE('CaptchaResponseValue') == "false") { header('location:index.php'); return; } ?> I even tried: $_COOKIE("CaptchaResponseValue"). The cookie is successfully set an...

Empty records are inserted at each load of the web page

I am having a registration page. when the page is loaded, everytime it tries to insert the values in the textboxes which is empty by default at first. Please help. My code is attached register.template.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; <html ...

[PHP / AJAX]: Change color of the message according to the entered text.

In my website home page, I have a new user registration Form. It contains a field "User Name". When the user enters the user name and the focus is pointed to another field, an AJAX code is executed that checks whether any user with the entered username already exists or not. The AJAX code that I am using is this: function toggle_userna...

Multistep form in PHP - MVC App

Hello, I'm about to program a mutistep form in my MVC App (Self-made MVC framework) in which no data is to be inserted until the last step is finished. I got the following issues/questions I'd really like to find a kind of pattern to solve this problem, is there any? I want it to be easy the perform a go back action, and get the data...

[PHP] Only allowing certain characters in string

Hi, I have been looking for a way to create a function to check if a string contains anything other than lower case letters and numbers in it, and if it does return false. I have searched on the internet but all I can find is old methods that require you to use functions that are now deprecated in PHP5. So how do we do it in PHP5? ...

Best Image type for GD?

I am using the GD Library to add text to the PNG Image of a Form, that i am using to create a pdf. My Tests show that using PNG, dosnt put to much of strain on the server just doing one, however i am concerned about scalability. So my question is does working with one file type have more overhead, than any of the others? ...

PHP stdClass question

Scenario: $x = json_decode( $x ); foreach ( $x as $item ) { $info[] = $item; //ERROR } I am looping though a datafeed to get the data. I want to add items to a stdClass object in a loop. How would I do that? I'm not that familiar with stdobj's. ...

Strange IF Statement behaviour

Hello All, I have an IF statement that consists of two separate function calls passing values to two variables. Obviously if neither value is 'FALSE' then the code block is executed: <?php class MyValidater { static function validateString($string) { if (preg_match("/[A-Za-z]+/", $string)) { return $string...

Using a MySQL trigger to update all fields matching a condition

Hi, What I am trying to do is to set the column of each insert query to the latest value of $i I've never used a trigger in MySQL before but I do believe that's the easiest way to do this. I would be open to other ideas and suggestions. Right now I have: $i = 1; foreach($_FILES["upload_project_images"]["name"] as $key => $name) { ...

Extending [Namespace]_Model_[Table] classes. is it safe?

Hello ladies and gentlemen! I'm new to php and zend framework and fill very uncertain about following: For example, I have two tables: table1: box(id, height, width, length, weight) table2: labels(id, boxid, text, position) labels.boxid -> box.id (labels.boxid is a foreign_key for primary_key box.id) I've generated two separate sta...

Counting rows in mysql

I have a mysql problem, my query looks as follows but not complete SELECT s.name, s.surname FROM students as s, practical as p, days_attend as d WHERE s.sid = p.sid AND s.sid = d.sid The scenario is the user may enter in a form to search how many days the student has been absent, eg if he enters 5 it will b...

Create ejabberd user from PHP

I need to create an ejabberd user from a PHP script. I also need to be able to add the new user to a predefined shared roster. Should I just call ejabberdctl using exec() or is there a better way? ...

Is it proper for a parent class to reference a property that exists only in the child?

In the project my team is currently working on, we're modifying a commercial PHP application. The app is strewn with code where a parent class checks for and works with a property that doesn't exist in the parent class, like so: class A { function doSomething() { if (property_exists($this, 'some_property')) { ...

How to do AES256 decryption in PHP?

I have an encrypted bit of text that I need to decrypt. It's encrypted with AES-256-CBC. I have the encrypted text, key, and iv. However, no matter what I try I just can't seem to get it to work. The internet has suggested that mcrypt's Rijndael cypher should be able to do this, so here's what I have now: function decrypt_data($data, $...

PHP Smarty - Get a list of all the variables in a template?

I'm using Smarty and PHP. If I have a template (either as a file or as a string), is there some way to get smarty to parse that file/string and return an array with all the smarty variables in that template? e.g.: I want something like this: $mystring = "Hello {$name}. How are you on this fine {$dayofweek} morning"; $vars = $smarty->ma...

PHP5: Adding stuff into a multidimensional array given a location of any length?

// given following array: $data = array( 0=>array( "data"=>"object1", "col"=>array( 0=>array( "data"=>"object2", "col"=>array( 0=>array( "data"=>"object3", ), 1=>array( "data"=>"object4", ), ) ), 1=>array( "data"=...

How to store a session value in the textbox when the page is loaded???

I am having a search text box. In that box, I want to store the previous search value when the page is loaded next time. For that i created session for the textbox value when the search button is clicked. But i dont know how to replace the session value in the textbox when the page is next loaded. Help me. Any help will be highly appreci...

object serialization in PHP (using __sleep)

I am having a difficult time getting object serialization to work properly. According to the documentation, I need to return an array of the variable names I want to serialize from the __sleep function. I did this, but as you can see from the first line of the output, my 50 is nowhere to be found. And when I attempt to unserialize that, ...

Kohana: setting the template name dynamically

Perhaps I'm just missing a basic OOP idea in PHP, but for the life of me, I can't seem to set the "$template" variable dynamically. If I extend the Template_Controller, I can set the template name like this: public $template = 'template_file_name'; But I can't set it dynamically like: public $template = $this->setTemplate(); or ...