Jump to content

Very strange database problems


xgd

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.