PHP Notice: Use of undefined constant dbserver - assumed 'dbserver' [duplicate] - php

This question already has answers here:
What does the PHP error message "Notice: Use of undefined constant" mean?
(2 answers)
Closed 9 years ago.
$CONFIG[dbserver] = 'localhost';
$CONFIG[dbuser] = 'test';
$CONFIG[dbpass] = 'rehrsdfvseg'
$CONFIG[dbname] = 'test';
I get this error, what can I do?
[20-Feb-2014 19:32:20] PHP Notice: Use of undefined constant dbserver - assumed 'dbserver' in /home/knul/public_html/porr/setup/config.php on line 2
[20-Feb-2014 19:32:20] PHP Notice: Use of undefined constant dbuser - assumed 'dbuser' in /home/knul/public_html/porr/setup/config.php on line 3
[20-Feb-2014 19:32:20] PHP Notice: Use of undefined constant dbpass - assumed 'dbpass' in /home/knul/public_html/porr/setup/config.php on line 4
[20-Feb-2014 19:32:20] PHP Notice: Use of undefined constant dbname - assumed 'dbname' in /home/knul/public_html/porr/setup/config.php on line 5

There is two possibilities.
Or your configuration are in array, and so you need to quote around the keys like this $CONFIG['dbserver']
Or dbserver etc are PHP constants, defined earlier with define function.

Related

A PHP Error was encountered Severity: Warning Message: Undefined property: stdClass:: $cancelled [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Notice: Undefined property - how do I avoid that message in PHP?
(7 answers)
Closed 7 months ago.
I got this error message when running PHP Code Igniter project:
A PHP Error was encountered
Severity: Warning
Message: Undefined property: stdClass::$cancelled
Filename: transactions/transtable.php
Line Number: 38
Backtrace:
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\views\transactions\transtable.php
Line: 38
Function: _error_handler
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\controllers\Search.php
Line: 103
Function: view
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\index.php
Line: 315
Function: require_once
Here is transactions/transtable.php
Line Number: 38
<td><?=$get->cancelled ? 'cancelled' : 'Completed'?></td>
If you are trying to bring something from the database with the model from the controller, you should look that the name of the variable that you bring before assign to the response of the controller (in the controller), need to be named exactly the same as the column name in database.
f.e:
if($query = $this->some_model->getModels(){
foreach($query->result() as $res){
$row = new stdClass();
$row->first_data = $res->THE_SAME_AS_IN_DB; (it's case sensitive too)
}
}
And in the model i usually use raw queries, but if youre using the CI functions, its the same name as the column in db.
Maybe if you post more info about the error, i can be more exactly, but some of the most typical reason of that error is because the variable is empty, and you try to use it .

How to fix Warning: Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP) in PHP? [duplicate]

This question already has answers here:
What does the PHP error message "Notice: Use of undefined constant" mean?
(2 answers)
Closed 4 years ago.
Warning: Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP) in /home/conteud2/public_html/include/meta.php on line 114
variate code using {var2[id]} no solution
Code in on comment below
You can check the issue on page https://www.conteudoanimal.vet.br/racaseespecies/anfibios/ver.php?id=5
Server runs PHP7 at moment
Thanks in advance for any help !
So it basically means that id isn't a constant.
It either should be $id, or 'id', also the var2 should be $var2.
Try the following code:
"{$var2['id']}"
Or
"{$var2[$id]}"

Trying to follow Google API guide to use phpmyadmin database to create markers [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 4 years ago.
I am trying to learn how to export from an Xampp phpmyadmin sql database to a google API to create markers.
I am trying to follow this guide:
https://developers.google.com/maps/solutions/store-locator/clothing-store-locator?csw=1
I get to the "Checking that XML output works" section.
I try to run my script by typing into my browser: http://localhost/projectgmaps/storelocator.php
This kicks out a page with:
*
Notice: Undefined index: lat in
C:\xampp\htdocs\projectgmaps\storelocator.php on line 4 Notice:
Undefined index: lng in C:\xampp\htdocs\projectgmaps\storelocator.php
on line 5 Notice: Undefined index: radius in
C:\xampp\htdocs\projectgmaps\storelocator.php on line 6 Fatal error:
Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\projectgmaps\storelocator.php:12 Stack trace: #0
{main} thrown in C:\xampp\htdocs\projectgmaps\storelocator.php on line
12
*
This is line 4,5,6:
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
and this is line 12:
$connection=mysql_connect (localhost, $username, $password);
Is anyone able to tell me what is wrong here?

PHP Notice: Use of undefined constant blocked [duplicate]

This question already has answers here:
What does the PHP error message "Notice: Use of undefined constant" mean?
(2 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
What is wrong with my code as I'm getting this error:
PHP Notice: Use of undefined constant blocked - assumed 'blocked' in /home/public_html/message.php on line 11
Your code is like,
$curblocked = $result[blocked];
But it should be like,
$curblocked = $result['blocked'];
just replace $result[blocked] with $result['blocked']

variable define error in PHP picture uploading [duplicate]

This question already has answers here:
What does the PHP error message "Notice: Use of undefined constant" mean?
(2 answers)
Closed 8 years ago.
I'm only a beginner with PHP and server side programming so excuse me for this question about variables. I was reading a tutorial about uploading a photo.
(tutorial on plus2net)
and like described in the tutorial i directly copied and pasted the code after understanding it. However the webpage filled with following errors after i inserted PHP in to the HTML.
Notice: Use of undefined constant size - assumed 'size' in C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 44
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 44
Notice: Use of undefined constant file_up - assumed 'file_up' in
C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on
line 45
Notice: Use of undefined constant name - assumed 'name' in C:\Program
Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 45
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 45
Notice: Use of undefined constant file_up - assumed 'file_up' in
C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on
line 47
Notice: Use of undefined constant size - assumed 'size' in C:\Program
Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 47
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 47
Notice: Use of undefined constant file_up - assumed 'file_up' in
C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on
line 51
This is the PHP Code:
<?Php
$file_upload="true";
$file_up_size=$_FILES['file_up'][size];
echo $_FILES[file_up][name];
if ($_FILES[file_up][size]>500000){
$msg=$msg."Uploaded file size more than 500KB<BR>";
$file_upload="false";}
if (!($_FILES[file_up][type] =="image/jpeg" OR $_FILES[file_up][type] =="image/png")){
$msg=$msg."Your uploaded file must be of JPG or PNG.<BR>";
$file_upload="false";}
$file_name=$_FILES[file_up][name];
$add="upload/$file_name"; //the path with the file name
if($file_upload=="true"){
if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)){
//do your coding here to give a thanks message
}
else{
echo "Failed to upload file.";}
}
else{
echo $msg;
}
?>
I've corrected the variable error but I'm getting this error now instead
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 44
Please guide me through this. :)
Where you have
$file_up_size=$_FILES['file_up'][size];
size is being interpreted as a constant due to the lack of a dollar sign.
What you want is
$file_up_size=$_FILES['file_up']['size'];
The problem is that you are relying on bare strings being interpreted as such. Normally, in PHP code, this is considered a constant:
echo FOO;
If you don't define that constant first, like this:
define('FOO', 'foo');
You will encounter this error and PHP will interpret it as a bare string and echo FOO. This is a bad choice. I think what you mean to do is use actual strings (rather than undefined constants) as your array indices:
if ($_FILES['file_up']['size']>500000){
// etc..
Which is what is recommended.
Note: Bare strings are covered in the manual entry for Arrays, specifically underneath the section Arrays do's and don'ts (the manual says don't do this).
This is wrong, but it works. The reason is that this code has an
undefined constant (bar) rather than a string ('bar' - notice the
quotes). PHP may in future define constants which, unfortunately for
such code, have the same name. It works because PHP automatically
converts a bare string (an unquoted string which does not correspond
to any known symbol) into a string which contains the bare string. For
instance, if there is no defined constant named bar, then PHP will
substitute in the string 'bar' and use that.

Categories