xgd Posted July 18, 2009 Share Posted July 18, 2009 Hello, I am trying out some scripts and basically when i change the database settings, the script doesnt seem to recognize it so i get an error saying that access is deined for a user and a password that is not even in the file (connect.hp). Why does that happen ? I tried other scripts from the same site and it worked fine. Here is the dodgy script: connect.php <? $db = mysql_connect("localhost", "voja", "kova") or die("Could not connect."); if(!$db) die("no db"); if(!mysql_select_db("cms",$db)) die("No database selected."); ?> and install.php <?php include "connect.php"; $installiptable="CREATE TABLE `CMS_IP` ( `ID` bigint(20) NOT NULL auto_increment, `IP` varchar(60) NOT NULL default '', `EntryID` bigint(20) NOT NULL default '0', PRIMARY KEY (`ID`) )"; mysql_query($installiptable) or die("Could not install tables"); $installarticles="CREATE TABLE `CMS_articles` ( `EntryID` bigint(21) NOT NULL auto_increment, `title` varchar(60) NOT NULL default '', `body` longtext NOT NULL, `shortdescription` mediumtext NOT NULL, `totalscore` decimal(20,0) NOT NULL default '0', `numvotes` bigint(20) NOT NULL default '0', `timesviewed` bigint(20) NOT NULL default '0', `CMS_tsubmit` varchar(255) NOT NULL default '', `CMS_telapsed` bigint(21) NOT NULL default '0', `CMS_author` varchar(255) NOT NULL default '', `avgvotes` float NOT NULL default '0', PRIMARY KEY (`EntryID`) )"; mysql_query($installarticles) or die("Could not install articles"); $installadmin=" CREATE TABLE `CMS_logintable` ( `id` int(5) unsigned NOT NULL auto_increment, `username` varchar(32) default NULL, `password` varchar(32) default NULL, PRIMARY KEY (`id`) )"; mysql_query($installadmin) or die("Could not install admin"); print "Everything is installed, please delete this file."; ?> and the script that works for example is this: connect.php <?php $db = mysql_connect("localhost", "voja", "kova") or die("Could not connect."); if(!$db) die("no db"); if(!mysql_select_db("cms",$db)) die("No database selected."); ?> and install.php <?php include "admin/connect.php"; $sql="CREATE TABLE P_question ( ID int(21) NOT NULL auto_increment, question varchar(100) NOT NULL default '', PRIMARY KEY (ID) )"; mysql_query($sql) or die("Questions not installed"); $sql2="CREATE TABLE P_ip ( ID bigint(21) NOT NULL auto_increment, IP varchar(40) NOT NULL default '', PRIMARY KEY (ID) ) "; mysql_query($sql2) or die("Table not installed"); $sql3="CREATE TABLE P_choices ( ID int(10) NOT NULL auto_increment, answer varchar(100) NOT NULL default '', votes bigint(21) NOT NULL default '0', PRIMARY KEY (ID) )"; mysql_query($sql3) or die("choices not installed"); $sql4="CREATE TABLE P_admin ( ID int(10) NOT NULL auto_increment, username varchar(15) NOT NULL default '', password varchar(255) NOT NULL default '', PRIMARY KEY (ID) )"; mysql_query($sql4) or die("Admin not installed"); print "Poll Installed"; ?> I even tried using the same databse as you can see but something is wrong with the firt example, it simply for some reason wont recognize the username and password. What do you think is the problem? Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/ Share on other sites More sharing options...
sKunKbad Posted July 18, 2009 Share Posted July 18, 2009 The first script uses php short tags. You might use a normal php opening tag and see if it makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-877708 Share on other sites More sharing options...
Psycho Posted July 18, 2009 Share Posted July 18, 2009 Well, the first script is using 'short' php tags which is not good practice, but that shouldn't create the type of error you are reporting. Based upon your explanation I am assuming it is the connect script that is failing. Have you tried just running those two connection scripts independantly to ensure the first one succeeds? If not, then you only need to concern yourself with that one. If yes, then the problem lies elsewhere. Also, have you considered this may be a caching issue? If you had incorrectly set up the file to use the wrong credentials initially and the error occured. You may still see that error after correcting the problem if your browser has cached the response. Try pressing Ctrl-F5 on the page to ensure the browser gets a frsh copy. Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-877710 Share on other sites More sharing options...
PFMaBiSmAd Posted July 18, 2009 Share Posted July 18, 2009 Posting the actual error message would help, but I'll guess that it is occurring on a mysql_query() statement because the actual connection is not being attempted due to the use of short open tags in that code. Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-877714 Share on other sites More sharing options...
xgd Posted July 19, 2009 Author Share Posted July 19, 2009 Hello people. Ok i get this error when i run the install.php: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\EasyPHP 3.0\www\install.php on line 9 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files\EasyPHP 3.0\www\install.php on line 9 Could not install tables I mean this is ridiculous. I few times i thought PHP was playing tricks on me when i wrote some scripts, but then i found that i had actually made a sily mistake somewhere, but this time it is beyond me. It simply doesnt get the username and password i put in the connect.php, and other scripts from this site work, but this one that is important does not!(go figure). So if i can get it working it would be really good. Oh yeah, but if i go straight to localhost/connect.php, it DOESNT DISPLAY ANYTHING, which basically means that it got connected to the db and selected it, otherwise it wouldve said "no db" and "n odatabase selected". What the hell is going on ? Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-877903 Share on other sites More sharing options...
xgd Posted July 19, 2009 Author Share Posted July 19, 2009 Also if someone is bothered to check out this little app on his own and see what the issue is, pm me your email so i can send it to you, its only 15kb. Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-877926 Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2009 Share Posted July 19, 2009 My post above told you that if the error is occurring on a mysql_query statement (which it is if you read the error message) that the problem is because of the short open tag <? being used in the code that contains the mysql_connect() statement. sKunKbad also told you the problem was likely the short open tag in the first reply in the thread. In case you have not got the message, only use full <?php tags. Change any <? to <?php Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-878056 Share on other sites More sharing options...
xgd Posted July 19, 2009 Author Share Posted July 19, 2009 YEA IT WORKS! But the original problem wasnt the short tag, because all scripts from this guy are like that an others worked. I changed the connect.php to use mysqli instead of mysql (the code currently is pretty old) to this: $dbc = mysqli_connect("localhost", "voja", "kova", "content"); if (!$dbc) { echo "bla bla"; } and also i changed the mysql queries in install to be: $r = mysqli_connect($dbc, $inserttable(or hatever the var was) etc. Thanks for letting me know about the short php tag problem, but all in all iwill have to change ALL Tthe queries in all the scripts of the application to get it working (bummer). At least it will work (hopefully); Quote Link to comment https://forums.phpfreaks.com/topic/166443-very-strange-database-problems/#findComment-878069 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.