murias Posted November 29, 2009 Share Posted November 29, 2009 Hello to all, thanx for taKing the time to read this and to assist. I feel like this is going to be more than likely a very simple thing, but has eluded me thus far. This code worked on my local development machine, but then I transferred it over to a FreeBSD machine, which I have just built and it does not function the same way. The exact errors I get are: Warning: mysql_query() [function.mysql-query]: Access denied for user 'murias'@'localhost' (using password: NO) in /usr/home/www/develop.develop/property/add_user.php on line 47 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /usr/home/www/develop.develop/property/add_user.php on line 47 Code from the script lines 2 and 42 through 47: include_once ('mysql.inc.php') ; $query = "INSERT INTO users VALUES('', '".$_POST["user"]."', " ."PASSWORD('".$_POST["password"]."')," ."'".$_POST["email"]."'," ."'".$_POST["management"]."', " ."'".$_POST["permission"]."', '', '', '')" ; $result = mysql_query($query); Code from mysql.inc.php: $db_hostname = "localhost:3306"; $db_database = "property_management"; $db_username = "property"; $db_password = "changedtoprotecttheinnocent"; $connection = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_database, $connection); function open_db_connection() { $connection = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_database, $connection); } function close_db_connection() { if ($connection) { mysql_close($connection) ; } } The path to the include file is correct. Permissions on the include are identical to those of the referrer. But have changed to 777 to test, and also attempted changing owner. This code as it stands worked on a my desktop under MAMP. Password and user in the include are correct: when I copy and paste it into the the actual script all of this works. What I find odd, is that the db user is actually property, it is like the server is denying the existence of the include, it is trying to use a different user, and not what is declared in the include. Again, if I put the very same connection data out of the include and put it exactly as is into the main script, it all works. It would be awesome if someone could direct me to what I am "blatantly" overlooking. Thank you greatly in advance. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2009 Share Posted November 29, 2009 You don't have a valid mysql connection at the time your mysql_query() is being executed. You are probably using short open tags <? in your mysql.inc.php file and the php code in it is not being seen as php code. Always use full php tags to avoid wasting your time when you move to a different server. Quote Link to comment Share on other sites More sharing options...
murias Posted November 29, 2009 Author Share Posted November 29, 2009 You are probably using short open tags <? in your mysql.inc.php file and the php code in it is not being seen as php code. Always use full php tags to avoid wasting your time when you move to a different server. Appreciate this. Although, I have verified my tags, and they are not the short tags. Opening: <?php and Closing: ?> Wishing that was it. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 You are going to need to post your whole actual code from the start of the file up through the line with the error if you want someone else to determine why it is not working. Based on the out of context code posted so far, all anyone can determine is that - You don't have a valid mysql connection at the time your mysql_query() is being executed. Quote Link to comment Share on other sites More sharing options...
murias Posted November 30, 2009 Author Share Posted November 30, 2009 You are going to need to post your whole actual code from the start of the file up through the line with the error if you want someone else to determine why it is not working. I had only posted so far what could be construed as mostly relevant, as to be nice. <?php include_once ('mysql.inc.php') ; //Input vaildation and the dbase code if ( $_GET["op"] == "reg" ) { $pass_verify = false; if ($_POST['password'] != $_POST['password2']) { $pass_verify = false; } else { $pass_verify = true ; } if ($pass_verify == false) { die( "Passwords chosen do not match. Please do try again."); } $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "0") { $bInputFlag = false; } else { $bInputFlag = true; } } // If we had problems with the input, exit with error if ($bInputFlag == false) { die( "Unfortunately, fields were left blank. " ."Please go back and try again."); } // Fields are clear, add user to database // Setup query $query = "INSERT INTO users VALUES('', '".$_POST["user"]."', " ."PASSWORD('".$_POST["password"]."')," ."'".$_POST["email"]."'," ."'".$_POST["management"]."', " ."'".$_POST["permission"]."', '', '', '')" ; $result = mysql_query($query, $connection); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 And the whole mysql.inc.php file. xxxxx out any sensitive information. What are the two functions doing in the mysql.inc.php code you posted? The first one should work, except that you cannot use the $connection variable outside of that function because it is not being returned by the function, but the close_db_connection function, as written, cannot work. We only see the information you provide in your post. To get help with what your code is doing, we need to see your code. There are probably 5,000,000+ php based web sites that are including a database connection file that works. That means something you are doing on your server is not working. Interestingly, the first time I tried your posted code, it did not attempt to execute the mysql_connect() statement in the include file and it was only after I went into the files and altered them by adding echo statements that it did execute the code as expected. I suspect that the editor you are using is not producing straight ASCII source code. Also, what php version, because php.net has had a lot of bugs in the _once versions of include/require. Quote Link to comment Share on other sites More sharing options...
murias Posted November 30, 2009 Author Share Posted November 30, 2009 full mysql.inc.php <?php //Database Settings $db_hostname = "localhost:3306"; $db_database = "property_management"; $db_username = "property"; $db_password = "XXXXXXXXX"; $connection = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_database, $connection); function open_db_connection() { $connection = mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error()); mysql_select_db($db_database, $connection); } function close_db_connection() { if ($connection) { mysql_close($connection) ; } } ?> and just in case at this point the full code. <?php include_once ('mysql.inc.php') ; global $connection, $db_hostname, $db_username, $db_password, $db_database; //Input vaildation and the dbase code if ( $_GET["op"] == "reg" ) { $pass_verify = false; if ($_POST['password'] != $_POST['password2']) { $pass_verify = false; } else { $pass_verify = true ; } if ($pass_verify == false) { die( "Passwords chosen do not match. Please do try again."); } $bInputFlag = false; foreach ( $_POST as $field ) { if ($field == "0") { $bInputFlag = false; } else { $bInputFlag = true; } } // If we had problems with the input, exit with error if ($bInputFlag == false) { die( "Unfortunately, fields were left blank. " ."Please go back and try again."); } // Fields are clear, add user to database // Setup query $query = "INSERT INTO users VALUES('', '".$_POST["user"]."', " ."PASSWORD('".$_POST["password"]."')," ."'".$_POST["email"]."'," ."'".$_POST["management"]."', " ."'".$_POST["permission"]."', '', '', '')" ; $result = mysql_query($query, $connection); // Make sure query inserted user successfully if ( !mysql_insert_id() ) { die("Error: User not added to database." . mysql_error()); } else { // Redirect to thank you page. Header("Location: add_user.php?op=thanks"); } } // end if //The thank you page elseif ( $_GET["op"] == "thanks" ) { echo "<h2>A new user had been registered!</h2>"; } //The web form for input ability else { echo "<form action=\"?op=reg\" method=\"POST\">\n"; echo "Username: <input name=\"user\" MAXLENGTH=\"32\"><br />\n"; echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n"; echo "Verify: <input type=\"password\" name=\"password2\" MAXLENGTH=\"16\"><br />\n"; echo "Email Address: <input name=\"email\" MAXLENGTH=\"32\"><br />\n"; echo "Management Company: <input name=\"management\" MAXLENGTH=\"4\"><br />\n"; echo "Permissions: <input name=\"permission\" MAXLENGTH=\"4\"><br />\n"; echo "<input type=\"submit\">\n"; echo "</form>\n"; } ?> I thought that I might have had an issue with my editor, using Coda, which might have been causing a white space issue, so I created a test file and test include and that had the exact same issue. These test files were created on the server using pico. I do not doubt that there I am doing or have done something wrong on the server. There are other packages running on the server that rely upon includes/requires and they are running just fine, ie phpmyadmin, postfixadmin, squirrelmail to just name a couple. The server is "freshly built", this is the first site I have attempted to move over from another server. Apache is running as www:www. version 2.2.13 php version 5.2.11 I have double checked php.ini and include_path does contain "." Any other information I can provide? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 While it does appear that you have error_reporting set to show all php errors (a problem with the include_once sould show up as a Warning message), add the following two lines of code immediately after the first opening <?php tag in the main file - ini_set("display_errors", "1"); error_reporting(E_ALL); Try the following syntax for the include (You are directly using the file name in this? You are not actually using a URL?) - include 'mysql.inc.php'; The global keyword has absolutely no meaning unless it is inside of a function definition (and even there it should not be used.) Remove your use of it in the main file. Do you in fact have more than one mysql.inc.php present on the server in any of the paths listed in the include_path? Perhaps one with only the open_db_connection() and close_db_connection() functions and NOT the in-line mysql_connect()/mysql_select_db() code? I have double checked php.ini and include_path does contain "."What does a phpinfo() statement show? (i.e. make sure of what the setting is at runtime in case the php.ini that you are looking at is not the same one that php is using.) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 Where in the include_path is the '.' ? If it is not the first entry and you have more than one mysql.inc.php on the include_path, then the mysql.inc.php that you are looking at is the one that is actually being included. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 There is a missing 'not' in the above post "... looking at is 'not' the one that ..." Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2009 Share Posted November 30, 2009 This is reaching a bit, but if the php code in mysql.inc.php is not being seen as php code but the include_once() is actually working, then the unparsed php 'code' would show up in the "view source" of the page in your browser. Also, add an echo statement of something in mysql.inc.php so that you get confirmation that the code in it is being executed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.