nothing works... host problem? *solved*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you can create a table in phpMyAdmin then you have privileges. If you can use the insert form in phpMyAdmin you have the necessary permissions. Try making a table and inserting data into it through the phpMyAdmin forms first. If that succeeds, try running a query hrough the query box in phpMyAdmin. If that works, then there is a problem in your code.
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

okay... it lets me put stuff in directly

i also ran a query with this:

Code: Select all

CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))
and it worked. so if that code worked in the query window, why won't it work otherwise?

EDIT:

I took out this from the code:

Code: Select all

// select the specific database name we want to access.
$dbname=$dbusername."_".$dbname;

now I am getting this
success in database connection.success in database selection.no table created.
Last edited by suthie on Sat Jun 09, 2007 5:39 pm, edited 1 time in total.
.Stealth
Forum Commoner
Posts: 57
Joined: Wed Jan 10, 2007 12:15 pm
Location: Manchester, England

Post by .Stealth »

suthie wrote:okay... it lets me put stuff in directly

i also ran a query with this:

Code: Select all

CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))
and it worked. so if that code worked in the query window, why won't it work otherwise?
most likley incorrect password/username
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Your host have either given you the wrong credentials for the database, or you're using the wrong credentials... Go back to your host and ask them why this is happening ;)
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

now i am getting slightly better results:

I took out this from the code:

Code: Select all

// select the specific database name we want to access.
$dbname=$dbusername."_".$dbname;
and now my code looks like this:

Code: Select all

<?php

// set your infomation.
$dbhost='localhost';
$dbusername='username';
$dbuserpass='mypassword';
$dbname='test';

// connect to the mysql database server.
echo "success in database connection.";

// select the specific database name we want to access.
if (!mysql_select_db($dbname)) die(mysql_error());
echo "success in database selection.";

// add a table to the selected database
$result="CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}

?>


now I am getting this
success in database connection.success in database selection.no table created.
so the problem must be somewhere in here:

Code: Select all

// add a table to the selected database
$result="CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

} else {
	echo "no table created. ";
	echo mysql_error();
}
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

success in database connection.Access denied for user 'vhostswww'@'localhost' (using password: NO)
thats wierd. thats a step backwards now.... and i did not put in user "vhostswww"

what does that mean?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

suthie wrote:// set your infomation.
$dbhost='localhost';
$dbusername='username';
$dbuserpass='mypassword';
$dbname='test';

// connect to the mysql database server.
echo "success in database connection.";
I don't see a call to mysql_connect().
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

wow, that was dumb of me. looks like i accidentally took that out when i took out another line.

Code: Select all

<?php

// set your infomation.
$dbhost='localhost';
$dbusername='david';
$dbuserpass='mypassword';
$dbname='test';

// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);
echo "success in database connection.";

// select the specific database name we want to access.
if (!mysql_select_db($dbname)) die(mysql_error());
echo "success in database selection.";

// add a table to the selected database
$result="CREATE TABLE users (username VARCHAR(25), password VARCHAR(25), email VARCHAR(30))";
if (mysql_query($result)){
echo "success in table creation.";
} else {
echo "no table created.";
}

?>
it works now!
Post Reply