Page 2 of 2
Posted: Sat Jun 09, 2007 5:19 pm
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.
Posted: Sat Jun 09, 2007 5:34 pm
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.
Posted: Sat Jun 09, 2007 5:38 pm
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
Posted: Sat Jun 09, 2007 5:38 pm
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

Posted: Sat Jun 09, 2007 5:41 pm
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.";
}
?>
Posted: Sat Jun 09, 2007 6:01 pm
by volka
try
Code: Select all
} else {
echo "no table created. ";
echo mysql_error();
}
Posted: Sat Jun 09, 2007 6:16 pm
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?
Posted: Sun Jun 10, 2007 5:03 am
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().
Posted: Sun Jun 10, 2007 7:50 am
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!