PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 14, 2022

[FIXED] Why am I getting this? Use of undefined constant connection - assumed 'connection'

 February 14, 2022     constants, mamp, mysql, php, undefined     No comments   

Issue

I am developing on a Mac OSX 10.5 in the MAMP environment. My PHPadmin shows that the database and table exist just fine, however when I try to execute a connection I get this:

NOTICE: Use of undefined constant connection - assumed 'connection'

Here is what I have for code:

In header before any HTML or white-space

//  1. Create a database connection
$connection = mysql_connect('localhost', 'test', '1234');
if (!connection) {
    die("Database Connection1 Failed: " . mysql_error());
}
//  2. Select a database to use
$db_select = mysql_select_db('widget_corp', $connection);
if (!$db_select) {
    die("Database Connection2 Failed: " . mysql_error());
}

In the body of HTML markup of the database connection page

//  3. Preform database Query
$result = mysql_query('SELECT * FROM subjects'. $connection);
if (!$result) {
    die("Database Connection3 Failed: " . mysql_error());
}
//  4. Use returned data
while ($row = mysql_fetch_array($result)) {
    echo $row["menu_name"]." ".$row["position"]."<br />";
}

After the closing HTML tag

//  5. Close connection
mysql_close($connection);

Solution

you said if (!connection) instead of if(!$connection)



Answered By - Zak
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing