I'm trying to make a simple JQuery JSON call with some HTML, JS, and PHP, but it seems like there's a bug in my createBuilding() function. One of the first thing the function does is create an alert box and not even that shows up. When I check the Javascript console I get Uncaught Reference Error. I made a JS Fiddle to see if anyone can help!
http://jsfiddle.net/LpFTj/1/
Thank you for all your help!
You seem to confining your function to the scope of DOM Ready event .. So you cannot access outside of .. Also a type in this element buildingType
var buildingFinalType = document.getElementById('builtingType').value;
Move createBuilding outside $(document).ready. Since it is defined in a function it is not available outside the scope of that function i.e. not globally available.
Related
I declared getLesediSimilarPropertyOnShow() function. When I run the application, I get this error below:
Fatal error: Cannot redeclare
GautengPropertyDB::getLesediSimilarPropertyOnShow() in
C:\xampp\htdocs\workspace\ajax-live-search\libs\GautengPropertyDB.php on line 4704
I deleted this entire function thinking about the duplication.
But when I tried to check if the function getLesediSimilarPropertyOnShow() exists by pressing CTRL+F, The Find and Replace Dialog Box displays Not Found in the current document. Meaning the function does not exist. But when I tried to reload the page, the same message persits and the line 4704 is located on comment lines outside of all functions that has nothing to do with the code. I thought may be it was previous error loaded in the cache memory and I cleaned the cache but the same error stands still. But the function does not exist in the file. I don't understand this phenomenon. Can someone please explain this?
At first use IDE like PHPStorm, that show for you where function declared.
Use http://php.net/manual/en/function.function-exists.php for check if function already declared
Yeah I know this is probably not the best way to perform this. However I have a script which I would like to call multiple times with parameters and hand over two variables. The code I have so far looks like this:
$testfeld = array('User1'=>'400028',
'User2'=>'400027'
);
foreach($testfeld as $key=>$value) {
$_GET['cmd'] = 'modify';
include("testmodify.php");
}
If I run this code, I get an error message:
Fatal error: Cannot redeclare show() (previously declared in testmodify.php:14) in testmodify.php on line 39
If I perform this, it only modifys me the first entry of the array and then throws me the error message above.
Sadly, I have only read access to testmodify.php.... So is there a way to perform this include with all the content of the array?
Put your code in the function, include it once and call as much as you want.
You are receiving this error because the file testmodify.php contains the definition for "show". A second inclusion of the file caused by your loop attempts to define the object show again, which cannot be done.
Here is another SO question about someone trying to redefine a function.
Php and redifining
Edit: the other answer by MilanG is how you could go about fixing it.
You can do something like (in your testmodify.php script):
if (!function_exists("show")) {
function show($parameters) {
/* do your stuff here */
}
}
A better thing to do, in this case, would be to perform include_once() in your testmodify.php script, making it point to a script file where you define your show() function. My approach should also work for you.
Hope that helps :)
I am correctly retrieving my data form Parse, however when trying to call the function getCreatedAt it doesn't work.
I am correctly retrieving other info like this:
$obj->get(' description');
But when calling getCreatedAt the page doesn't work and throws this error:
__toString() must not throw an exception
I have tried getting the timestamp like this
$obj->get('createdAt');
$obj->getCreatedAt();
But none worked.
Does anyone know what may be going on?
Found the solution.
I am using laravel and I was trying to print the Datetime which is not possible, as it is an object.
Instead of calling
{{$obj->getCreatedAt()}}
You can just call
{{$obj->getCreatedAt()->format('Y-m-d H:i:s')}}
Thanks for your answers!
I am creating a function that converts a users initials (STRING) to their userid (INT)
problem is when I call the function I get a call to undefined func error because the below declared function is no where to be found in the Source!
// connect to database -- this works, I checked it
function convertRadInitToRadID($radInits){
$sqlGetRadID="SELECT id FROM sched_roster WHERE radInitials == '".$radInits."'";
$resultGetRadID=mysql_query($sqlGetRadID);
$radID=mysql_result($resultGetRadID,0);
return $radID;
}
...I then create and array ($radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter) of user initials, it works with no errors I tested it independently
$randKey=rand(0,(count($radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter)-1));
$randRad=$radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter[$randKey];
$randAssignedRadID=convertRadInitToRadID($randRad); // call to undefined function error here
when I view source the function definition code (where I define the function) is nowhere to be seen in the source. Very strange. I tried placing it around different areas of the script, same error. The function definition is declared appropriately and is wrapped in .
Very strange. The function just doesn't appear. Quotations, syntax, semi-colons, etc are all spot on.
No syntax errors. Advice?
I Strongly agree with Answer #1.
In addition a usual problems occur in php if you are defining function after calling it. i.e. your calling code is before function defination then it will not run and will give an error of undefined function.
You can create a class then define this function in that class and on the time of calling you can call that function with help of $this->function(args)
I think this will resolve your problem in mean while i am trying to run your code on my machine, lets see what happen
May be your function is a method of some class. So, if it is, you should use it in another way:
MyClass::convertRadInitToRadID($radInits) // if static method
or like this
$class = new MyClass();
$class ->convertRadInitToRadID($radInits)
Trying to make sense of your question... Are you trying to call the function using JavaScript? If so, remember that JavaScript is run on the browser, and PHP is run on the server (and this is why when you "view source" you don't see the function anywhere). To send data back from JavaScript to PHP you should use AJAX.
I found the answer: I was using Jquery UI tabs.... there must be a conflict with tabs. When I run the code without tabs there is no issue.
Thanks for the '==' fix.. appreciate it. my bad
thanks for reminding me about the 80 char varname code limit
I'm working with 0.9.5 and I'm doing some phpunit tests.
When I execute my second test, that invokes again the webservice, I'm getting this error:
Undefined index: _transient
/var/www/dev_folder/nusoap/nusoap.php:227
/var/www/dev_folder/nusoap/nusoap.php:7293
when
$client = new nusoap_client($this->_config->URL_Path . $webserviceWSDL, true);
is executed by a second time.
I checked nusoap.php and seems something related with globals or something static or singleton... but I don't know what can I do to solve the problem...
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
Need nusoap client to be unloaded or something like this? Why this global variable is failing?
Thank you.
I had the same problem. The comments seemed to indicate that the global variable was an attempt to emulate a static class variable, so I simply updated the code to actually use a static class variable in the nusoap_base class. That seemed to do the trick.
You can checkout the code here.