FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


setup.php





Saber
I dont have a clue why this stoped working. I have tired to test it different ways and it still doesnt work... Please someone help, I need this working for class in the morning.

Quote:
Code:
<?php
include("db.php");
$con = mysql_connect(localhost, $username, $password);
if (!$con) {
   die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';

$db_selected = mysql_select_db($database, $con);
if (!$db_selected) {
   die ('Cant use $database : ' . mysql_error());
}

$query="CREATE TABLE `newspost`
(`id` int(6) NOT NULL auto_increment,
`newstitle` varchar(50) NOT NULL,
`loginname` varchar(40) NOT NULL,
`date` varchar(50) NOT NULL,
`news` text(500) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE id (`id`),
KEY id_2 (`id`))";
echo $query;

//mysql_query($query);
if (mysql_query($query)){
echo "success in table creation.";
} else {
echo "no table created.";
}
mysql_close($con);

?>
Traveller
Perhaps if you told us the actual symptoms we might be able to be of assistance with what (from what you have stated) appears to be your homework. LOL!

Without further information, from what I can see, it may not work because you have already tested it once, and the table you are trying to create already exists.
Saber
well I had everything working right. Then put all my files from kodamakage.frih.net to kodamakage.com.(I stupidly deleted all the databases) at this point it stoped working. When I made the database again and ran the setup it says that it can connect to the database, but it wont make the table.(checking in phpmyadmin to see if there really was a table or not.) I have tried changing the names of things, and still nothing.
krazycapital
Here is one problem:
Code:
<?php
include("db.php");
//The quotes on this line
$con = mysql_connect('localhost', $username, $password);
if (!$con) {
   die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';

$db_selected = mysql_select_db($database, $con);
if (!$db_selected) {
   die ('Cant use $database : ' . mysql_error());
}

$query="CREATE TABLE `newspost`
(`id` int(6) NOT NULL auto_increment,
`newstitle` varchar(50) NOT NULL,
`loginname` varchar(40) NOT NULL,
`date` varchar(50) NOT NULL,
`news` text(500) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE id (`id`),
KEY id_2 (`id`))";
echo $query;

//Try without these // too on the next line
//mysql_query($query);
if (mysql_query($query)){
echo "success in table creation.";
} else {
echo "no table created.";
}
mysql_close($con);

?>
kv
Use mysql_error() to print the exact error. If there is a connection or permission problem, you will come to know.
Traveller
Saber wrote:
When I made the database again and ran the setup it says that it can connect to the database, but it wont make the table.



General path of troubleshooting:
  1. Did it ever work before?
  2. NO: Something was wrong from the very beginning, and the entire installation needs to be checked for correctness.
  3. YES: In order for something to have stopped working, something must have changed.
    1. When was the last time it worked correctly?
    2. When was the FIRST time to didn't work correctly?
    3. What changed between those two times?
      1. Hardware
        • Changes to existing system?
        • Moved to a different system?

      2. Software?
        • Changes to the software in question?
        • Addition, removal, or modification of any other, existing software?

      3. Database?
        • Location?
        • Access?
          • Username, password, and database name?
          • Privileges assigned to user?
        • Structure?


    Of course, the above is not exhaustive, but the important thing for you to determine is: "What is different between the instance where your code worked, and the instance where it did not?"

    Good luck.
Saber
@Traveller
1. Yes it was working fine, about ten minutes before I posted.
3a. 10 minutes ago from my first post.
3b. when I remade the database.
3.1.both were on fri hardware.
3.2. Have no idea.
3.3. same location, same username, etc.

@kv thanks for that idea, forgot about that..
"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(500) NOT NULL, PRIMARY KEY (`id`), UNIQUE id (`id`), KEY id_2"

@krazycapital if I took out the // in //mysql_query($query); wouldnt that just be trying to run the query two times?

so yah..... for the moment I did a quick fix and made the text a varchar... But that wont work for everything... So what was I stupidly doing wrong with the text? And thanks again for all your help. I would have just given up and failed the project.
Traveller
Saber wrote:

3b. when I remade the database.


I wasn't actually expecting you to post answers to each of the questions, but for you to ask yourself those questions as a means of assessing the nature of the problem.

Since you supplied answers, however, the 3b is quite telling: the first time it stopped working was after you remade the database. Remember: the primary question at each stage of this kind of troubleshooting is "What changed?" In this case, you already know that the database changed, since you changed it. Since the code stopped working after that, and you did not change the code, then it was very likely something about the NEW instance of the database that caused the problem (e.g. maybe "newstitle" was named as "news_title" in the new instance, or something else along those lines). The main idea is that, as long as nothing changes, computers will always do the same thing. Thus, if what they DO changes, then some other changes has caused that to happen.
mathiaus
Try changing the query to this

Code:
$query="CREATE TABLE `newspost` (
`id` INT( 6 ) NOT NULL AUTO_INCREMENT ,
`newstitle` VARCHAR( 50 ) NOT NULL ,
`loginname` VARCHAR( 40 ) NOT NULL ,
`date` VARCHAR( 50 ) NOT NULL ,
`news` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
)";
 
NG
change to this





Code:
query="CREATE TABLE `newspost` (
`id` INT( 6 ) NOT NULL AUTO_INCREMENT ,
`newstitle` VARCHAR( 50 ) NOT NULL ,
`loginname` VARCHAR( 40 ) NOT NULL ,
`date` VARCHAR( 50 ) NOT NULL ,
`news` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
)";



rmb scripting ownzz u



www.rmb-forum.net.tc
Related topics
phpBB Not Working
[RESOLVED] Need Help with pphlogger
Jaki portal php polecacie?
Setup php,mysql and others...
script kurulum ve anlatýmý
Installing Burning Board Lite
SquirrelMail SpamFilter Issue
Webwinkel
Mac OSX v10.6 (Snow Leopard)
Splitting large site over more than one servers
How to Setup PHP n MY SQL work on Windows 7 system
which host do u like put php&mysql?
Any Support for Joomla 3.0 Magic Qoutes problem?
Joomla 3.0 article image problem.. MAGIC QOUTES
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.