php,codeigniter,viewRelated issues-Collection of common programming errors
Emanuil Rusev
php function
In CakePHP there is a (quite fundamental) method called find. Most of the time this method would return an array but if you pass count as the first parameter the method would return a different data type – an integer.The method is allowed to return various data types.Isn’t that bad?
jela
php
given the following script<?phpini_set(‘display_errors’,’On’); error_reporting(E_ALL);thisisanerror?>I get the expectedNotice: Use of undefined constant error – assumed ‘error’ in /htdocs/test.php on line 8but if I add something to the script<?phpini_set(‘display_errors’,’On’); error_reporting(E_ALL);errorfunction test () {echo(‘test’);}?>I getHTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.Why am
Alan Moore
php regex
I’m working on a simple project to teach about XSS. I’m trying to make a regex that will catch <script>alert(‘anything’)</script>;I crafted: <script>alert\(\'[\w!@#$%^&*()-=+]+\’\);</script> but when i try to implement it in php I get errors yet when I try it in a regex tool it says it matches my string.Anyone know how to make a regex that works?Thanks
Mr Biscuit
php session variables if-statement phpmyadmin
I am trying to create a user login page. Upon successful registration admins are assigned a value of “A” in my database and customers a “C”. Upon successful login customers will be directed to one page and admins to another. I created three session variables, their userId, userFName and their userType. I want to create an if statement to check the value of userType and have tried everything but I still get the error message “Parse error: syntax error, unexpected T_ELSE…on line 74”.`//create a
Dominic Rodger
php variables scope
I have a function with a big hierarchy:function func(){$a= 0; // Here the variable is 0while(…){echo $a; // gives me always 0for(…){if(…){if(…){$num = func3();$a = $num; // this $a does not corrospond to $a in the beginning}}}} }Does anyone know how I can change the value of $a from the nested scopes?
skaffman
php exception-handling
When throwing a new exception is it best to simply return true if no exception needs to be thrown. Alternatively is it best to return false instead of throwing an exception. Im using php.
noloader
php sqlsrv
I have experience with mysql databases and have successfully connected to them with a couple dozen projects. Now, I’m having trouble connecting to a SQL Server 2007. This works: <?php phpinfo(); ?> and the sqlsrv and pdo_sqlsrv sections appear on this page. Here’s the code that I’m using to connect: <?php $serverName = “serverName\sqlexpress”; //serverName\instanceName $connectionInfo = array( “Database”=>”dbName”, “UID”=>”userName”, “PWD”=>”password”); $conn = sqlsrv_connect(
Chimera
php function types parameters casting
This might sound like a silly question to many of you, but it keeps me wondering why PHP does not allow typecasting in its function parameters. Many people use this method to cast into their parameters:private function dummy($id,$string){echo (int)$id.” “.(string)$string }Orprivate function dummy($id,$string){$number=(int)$id;$name=(string)$string;echo $number.” “.$name; }But looking at many other programming languages, they accept typecasting into their function parameters. But doing this in PH
Sumurai8
php apache .htaccess codeigniter error-handling
My website has been slowed down a little last couple of days. I’ve looked into my error log and found lots of these:[Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace. [Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/
jcrane
php forms sed submit isset
With a good deal of help I have created a script that edits a file on my VPS. It has been working great but I have one issue that has me totally stumped. When I need to adjust a value in the file to 0 it will not work. Pretty much any other value will work (i.e. value=”3″) except 0 (value=”0″). I’m very confused. I need to have the script change the color= value to color=0 I have no idea why 0 won’t work but any other number or letter will. Here is my code:<?php //Color$color = explode(“=”, t
Sumurai8
php apache .htaccess codeigniter error-handling
My website has been slowed down a little last couple of days. I’ve looked into my error log and found lots of these:[Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace. [Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/
SideDishStudio
jquery ajax codeigniter jquery-ajax
So I’m using .load() to call a CI method to load some code into a div like normal. CI loads the correct content into the div UNLESS there is a trailing slash on the class, then it actually ignores the method I am loading and loads the default method in that class … ie:THIS WORKS FINE:I call .load(‘http://domain.com/class/ajaxmethod’)from domain.com/class/methodTHIS DOES NOT:I call .load(‘http://domain.com/class/ajaxmethod’)from domain.com/class/method/It will actually load http://domain.com/cl
JJD
json codeigniter codeigniter-datamapper
var data = xhr.responseText;When I output this console.log(xhr.responseText). Below is my output [“{id:1,name\”:\”JOHN\”,\”city\”:\”null\”}” ,”{\”id\”:2,\”name\”:\”MICHEAL\,\”city\”:\”null\”}”]How do I get id, name. I tried like this data.id but I get this error jquery JSON.parse: unexpected end of data.UpdateI am using code igniter with data mapper so my data mapper is giving that json response. Do you know, how I can resolve it.
Rocket Hazmat
codeigniter
I’m trying to get the id of last inserted record in the Db. But i’m getting the errorParse error: syntax error, unexpected T_RETURN in Z:\www\CI4\application\models \report_model.php on line 69my model:function getLastInserted() { $query =”SELECT $id as maxID from info where $id = LAST_INSERT_ID()”return $query; //line 69}my controller:function index(){ $id=$this->report_model->getLastInserted();$this->load->view(‘u_type1’,$id);}
hakre
php codeigniter codeigniter-2
I am new to codeigniter and trying to access data from mysql databasehere is my model class codefunction model_data($a){ $this->load->database(); $query = $this->db->query(“SELECT* FROM mytable3”); return $query->result(); }function model_data_cat(){ $this->load->database(); $query = $this->db->query(“SELECT* FROM mytable1”); return $query->result(); } Actually i am calling two functions in my controller. one is model_data and the other is model_data_cat. bu
Yeshwanth Venkatesh
php ajax codeigniter form-validation
I am trying to validate a form and save it in my database. I am using codeigniter’s validation library and it fails. this is the ajax function inside the view function save_form(){ $.ajax({url: ‘/projects/cafe/index.php/welcome/save_form’,type: ‘post’,data: {‘fname’ : $(‘#fname’).val(),’lname’ : $(‘#lname’).val(),’story_name’ : $(‘#story_name’).val(),’email’ : $(‘#email’).val(),’address_street’ : $(‘#address_street’).val(),’city’ : $(‘#city’).val(),’state’ : $(‘#state’).val(),’zip’ : $(‘#zip’)
teresko
php codeigniter error-handling relative-path
I am using code igniter, and I need to be able to read and/or include some html files, so I created an includes directory in the application folder. Using CI what is the best way to access this directory?In my controller I have tried:private $cms_temp_folder = APPPATH . ‘includes/’;But that gives me the error:Parse error: syntax error, unexpected ‘.’, expecting ‘,’ or ‘;Am I approaching this right, or should I be doing it another way?
user2247326
php css html5 codeigniter zend-framework2
I always have this error:Parse error: syntax error, unexpected T_STRING in /home/user/public_html/nameofsite/application/libraries/Zend/Barcode/Barcode.php on line 10Here is my controller code for generating barcode:public function testbarcode() {require_once(‘./application/libraries/Zend/Barcode/Barcode.php’);//adjust the above path to the correct location$barcodeOptions = array(‘text’ => ‘ZEND-FRAMEWORK’);$rendererOptions = array();Zend_Barcode::factory(‘code39’, ‘image’, $barcodeOptions, $
user1557970
php mysql json codeigniter getjson
I have developed a function in my Codeigniter web site, to request data through an API call to retrieve timeline data stored in a mysql table. My json respond is not coming out correctly. I need to create a json response to a $.getJSON, I done this in php . Below is the code that I wrote to get data from mysql and create a json response.public function index_get() {$rs = mysql_query(“SELECT headline, type, text, media, credit, caption FROM media”); $timeline = ‘{ “@headline”: “‘ . $row[ ‘headlin
Luis Martin
php codeigniter inheritance protected
I can use at least two basic ways to access a protected class method from a child class:parent::myMethod();$this->myMethod();If I don’t need to override it in the child class, in which case I would have to do this:function myMethod() {…parent::myMethod();… }which is the most recommended way to call it? I personally feel more comfortable using parent::myMethod() rather than $this->myMethod, because the first one immediately tells me this method is being inherited. But I’m not sure which wa
bouvard
mvc model view controller components
Question number three in my quest to properly understand MVC before I implement it:I have two cases in mind:The primary application window needs to launch the preferences window. (One View invoking another View.) The primary Model for an application needs to access a property in the preferences Model. (One Model accessing another Model.)These questions are related in that they both involve communication across Model-View-Controller triplets, a topic that I haven’t found much discussion of in my
George W Bush
mysql database view phpmyadmin
Is that a Good practice to change the Structure of the View at Run Time?I have created a VIEW CREATE VIEW freligiouschk AS SELECT user_id, religion, caste FROM freligious WHERE religion IN (‘Christian-Protestant’,’Christian-Orthodox’,’Hindu’,’Parsi’,’Christian-Others’) OR caste IN (‘Rajput’,’Kurmi/Kurmi Kshatriya’,’Veluthedathu Nair’,’Kuruhina Shetty’,’SKP’)The view is created When a user clicks a button those values in the conditions with change Like thisCREATE VIEW freligiouschk AS SELECT user
Infernus
view orientation
I have unexpected problem with obtaining view’s dimensions on orientation change. I have my custom ImageView. In onDraw() method I get view’s width and height via getWidth() and getHeight() and using these values I scale and move my image. On activity’s onConfigurationChange() I simply call setImageBitmap(bmp);Everything is fine with that, but sometimes when orientation has changed, my ImageView in onDraw() still remember old values of it’s width and height. How can I update it?
Bavarious
cocoa-touch debugging view retain
I ran into a bug I have trouble explaining. Now that I found the bug, I can certainly fix it but I would like to understand how such a thing could even happen.My code: NSLog(@”1 – self.nextPlayerButton = %@”,self.nextPlayerButton);NSLog(@”[self.view setUserInteractionEnabled:TRUE] with self.view=%@”,self.view);[self.view setUserInteractionEnabled:TRUE];NSLog(@”2 – self.nextPlayerButton = %@”,self.nextPlayerButton);where nextPlayerButton is defined as:@property (retain) IBOutlet UIBarButtonItem
Bill the Lizard
android layout view relativelayout
I’m trying to achive the following programmatically (rather than declaratively via XML):<RelativeLayout…><TextView …android:id=”@+id/label1″ /><TextView …android:id=”@+id/label2″android:layout_below: “@id/label1” /> </RelativeLayout>In other words, how do I make the second TextView appear below the first one, but I want to do it in code:RelativeLayout layout = new RelativeLayout(this); TextView label1 = new TextView(this); TextView label2 = new TextView(this); … l
Hassan Mokdad
database oracle database-design view oracle-sqldeveloper
I am using the following query to create an oracle view in oracle sql developer,select * from (SELECT DATEENTER as PI_TIMESTAMP,PI_TAG as PI_TAGNAME, case when LENGTH(TRIM(TRANSLATE(final, ‘ +-.0123456789’, ‘ ‘))) is null then cast(final as number) else null end as PI_VALUE, STATUS AS PI_STATUS FROM T2) a where PI_VALUE is not nullThe query is working fine in a query window, however it is giving me the error Error(s) parsing SQL: Unexpected token at 134 near ). Unexpected token at 136 near
Bob
android view onclick nullpointerexception
Some users are getting this error.I use a viewgroup to continuously display a banner add.I then use child views for the program and switch back and forth between views as the user clicks a button.I can cause a crash by switching back and forth between child views 6 to 10 times.Here is the layout for the viewgroup:<?xml version=”1.0″ encoding=”utf-8″?><LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”xmlns:myapp=”http://schemas.android.com/apk/res/com.company.pro
Chetan
ruby-on-rails view syntax-error crud
In my contactlist CRUD application, all the contacts are shown properly when i type the following URL: localhost/contactHowever, I want to have two options for each contact- either to update the information or to delete the record. So once i click on contact,say- “Chetan”, i want to go to a ‘showmain’ page with two options- Update(linking me to an update page) and Delete(linking me to a del page).My controller is as follows:-class ContactController < ApplicationControllerdef index@contacts=C
user1001635
android listview view back
hi guys after i call the method onKeyDown and my app closes without get me back error, this my code:public boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {if (expList.getVisibility() == View.VISIBLE){expList.setVisibility(View.INVISIBLE);}else{//}}return super.onKeyDown(keyCode, event); }
H Bellamy
ios view uiviewcontroller
Sorry for the waffley title.I have an issue with my iOS app. I use this code to change view controller and set some labels texts:UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; NSString *date = cell.textLabel.text; NSString *entry = cell.detailTextLabel.text;if (self.detailsViewController == nil) {DiaryDetailsViewController *d = [[DiaryDetailsViewController alloc]initWithNibName:@”DiaryDetailsViewController”bundle:[NSBundle mainBundle]];self.detailsViewController = d; } [se
Web site is in building