BigBoyMarky Posted June 14, 2013 Share Posted June 14, 2013 Hey, I am really new to PHP and I really don't know what I am doing (and yes this is my first time here). I am the only person that can even attempt to understand these kinds of things because I am a computer science major while the rest of my organization is no where near being affiliated with computers (all they know how to do is get a blue screen and give up and buy a new one). I am here to ask for help as the server that is hosting my organization's website is phasing out PHP4 and is now moving on the PHP5. When my organization's website was first coded, it was coded in PHP4 I believe and now after they have semi-phased out of PHP4, some of the tabs on the website don't necessarily work properly. As you can see (I guess you can't really see), when I click on a tab, the page shows up as "Unable to SELECT table." As far as I understand, PHP4 scripts should work in PHP5 environments because PHP5 is mostly backwards compatible. Okay so I was looking through all the PHP scripts and figured that it wasn't the way the table is coded that is at fault. I then noticed that every page that had that error had accessed the mysql database (I really don't understand databases either). So now I am leaning towards thinking that the database could be the problem or maybe the way the assigning variables is wrong. I feel like if I released code it would be bad for my organization so I will try to refrain from doing so. But if anyone can possibly give me a hint as to what may be causing the "Unable to SELECT table" problem I would really appreciate it. Thanks! Mark Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/ Share on other sites More sharing options...
jcbones Posted June 14, 2013 Share Posted June 14, 2013 There is no way of even giving a clue without first seeing code snippet, at the very least. This is because of the vast amount of ways you could interact with databases in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436014 Share on other sites More sharing options...
mac_gyver Posted June 14, 2013 Share Posted June 14, 2013 (edited) As far as I understand, PHP4 scripts should work in PHP5 environments because PHP5 is mostly backwards compatible. that's correct, except that early versions of php introduced a number of short-cuts that were depreciated, turned off by default, with some having finally been removed in the latest php5 version. so actually, well written and up to date php4 scripts should work in php5. you will need to debug each problem or simply go through each script and update it taking into account the deprecated features the code may be using (this will require that you have knowledge of what these features are and can identify where they are being used at in the code). if you want us to help, you need to post specific code and any errors or incorrect result it produces. Edited June 14, 2013 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436015 Share on other sites More sharing options...
ginerjm Posted June 14, 2013 Share Posted June 14, 2013 You're probably running in a prod environment, You need to work in a devl environment and turn on error checking and then take the info that you get from that to isolate the php line that is causing the problem. The error you describe is not a normal error, ie I've never seen that exact wording in a message. So - when you find the line and read up on that you may have your answer, otherwise you can at least show us the line. Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436042 Share on other sites More sharing options...
BigBoyMarky Posted June 15, 2013 Author Share Posted June 15, 2013 Thanks for the replies guys and here might be the problem (I think it's okay to release this part of the code) $getorder = "select * from hp_content order by hp_order"; $get_query = mysql_query($getorder) or die(mysql_error() . "<br>unable to get content"); $orderexist = mysql_num_rows($get_query); ?> <table cellspacing="0" cellpadding="0" border="0" width="521"> <?php if ($orderexist > 0) { while ($result = mysql_fetch_array($get_query)) { $hpid = $result[hp_ctid]; $title = nl2br(stripslashes($result[hp_title])); $content = nl2br(stripslashes($result[hp_para])); $order = $result[hp_order]; ?> <tr> <td><br> <table cellspacing="0" cellpadding="0" border="0" width="500"> <tr> <td class="orangetitle"><?=$title?></td> </tr> <tr> <td><br> <?=$content?> </td> </tr> </table><br><br> </td> </tr> <tr> <td><img src="images/single_hr.gif" width="521" height="10" alt="" border="0"></td> </tr> <?php } } ?> </table> I think it has something to do with the interaction with the database but I'm not too sure what's wrong cause as I've said I really don't know what I'm doing.. Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436088 Share on other sites More sharing options...
BigBoyMarky Posted June 15, 2013 Author Share Posted June 15, 2013 Thanks for the replies guys and here might be the problem (I think it's okay to release this part of the code) $getorder = "select * from hp_content order by hp_order"; $get_query = mysql_query($getorder) or die(mysql_error() . "<br>unable to get content"); $orderexist = mysql_num_rows($get_query); ?> <table cellspacing="0" cellpadding="0" border="0" width="521"> <?php if ($orderexist > 0) { while ($result = mysql_fetch_array($get_query)) { $hpid = $result[hp_ctid]; $title = nl2br(stripslashes($result[hp_title])); $content = nl2br(stripslashes($result[hp_para])); $order = $result[hp_order]; ?> <tr> <td><br> <table cellspacing="0" cellpadding="0" border="0" width="500"> <tr> <td class="orangetitle"><?=$title?></td> </tr> <tr> <td><br> <?=$content?> </td> </tr> </table><br><br> </td> </tr> <tr> <td><img src="images/single_hr.gif" width="521" height="10" alt="" border="0"></td> </tr> <?php } } ?> </table> I think it has something to do with the interaction with the database but I'm not too sure what's wrong cause as I've said I really don't know what I'm doing.. Okay I looked a little more and the error "Unable to SELECT table" is actually a DIE() function inside a php script called db_connect.inc.php (it was something that the previous coder included) So I guess when I select the database it doesn't work and therefore it outputs "Unable to SELECT table" (looks sort of like a try catch to me since I like my Java) The code above is inside the index.php script and above that code snippet there is also something that's similar to an include statement require "inc/db_connect.inc.php"; Here is what it says inside the db_connect.inc.php script mysql_select_db("(this is the database name)",$db) or DIE("Unable to SELECT table"); I'm not too sure if I'm being helpful or not... but thanks to everyone that is trying! Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436089 Share on other sites More sharing options...
mac_gyver Posted June 15, 2013 Share Posted June 15, 2013 if you temporarily change that line to the following it should tell you why the statement is failing - mysql_select_db("(this is the database name)",$db) or DIE(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436095 Share on other sites More sharing options...
BigBoyMarky Posted June 15, 2013 Author Share Posted June 15, 2013 if you temporarily change that line to the following it should tell you why the statement is failing - mysql_select_db("(this is the database name)",$db) or DIE(mysql_error()); Thank you for the reply the error says that access is denied to the database so I'm guessing I only have to allow access and it should work? Or is there something wrong with the way I pass objects? I read somewhere that in PHP5 you have to pass by reference? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436098 Share on other sites More sharing options...
ginerjm Posted June 15, 2013 Share Posted June 15, 2013 That kind of message says : a - the database name doesn't exist or b - you didn't connect to the sql server, as in the 'connect' statement above that select didn't work. Perhaps the permissions have changed on the sql server, or the credentials in the connect statement got changed somehow. Be sure that you are doing an error check on that connect statement. (as one should on every statement!) Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436125 Share on other sites More sharing options...
BigBoyMarky Posted June 15, 2013 Author Share Posted June 15, 2013 (edited) That kind of message says : a - the database name doesn't exist or b - you didn't connect to the sql server, as in the 'connect' statement above that select didn't work. Perhaps the permissions have changed on the sql server, or the credentials in the connect statement got changed somehow. Be sure that you are doing an error check on that connect statement. (as one should on every statement!) Thanks for the reply! Here's the connect statement above $db = mysql_connect("xxx","xxx","xxx") or DIE("<h1>Under construction. Please come back later!!</h1>"); Is it weird that I can't even ping db87.perfora.net? AND JUST TO CLARIFY I am not the original coder of the website it was coded by someone back in I believe 2003 and now I am left with no information other than how to FTP into the server and edit files.. Edited June 15, 2013 by ignace Removed credentials though it won't matter Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436145 Share on other sites More sharing options...
Solution mac_gyver Posted June 15, 2013 Solution Share Posted June 15, 2013 if those are your actual database credentials, go change them now. you cannot ping the database server at it's hostname because only specific ip addresses, such as your web server's, should have permission to connect to the database server. because your connect statement has error checking logic, that means that the connection worked and the select_db statement is failing due to a permissions problem. did you add that database username to the database you are trying to select and give it any permissions? depending on the method you are using to configure your database, you may also need to flush the permissions after altering them to get them to take effect. Quote Link to comment https://forums.phpfreaks.com/topic/279162-unable-to-select-table/#findComment-1436148 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.