nothing works... host problem? *solved*
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
okay... it lets me put stuff in directly
i also ran a query with this:
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:
now I am getting this
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))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.
most likley incorrect password/usernamesuthie wrote:okay... it lets me put stuff in directly
i also ran a query with this:and it worked. so if that code worked in the query window, why won't it work otherwise?Code: Select all
CREATE TABLE address_book (first_name VARCHAR(25), last_name VARCHAR(25), phone_number VARCHAR(15))
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
now i am getting slightly better results:
I took out this from the code:
and now my code looks like this:
now I am getting this
I took out this from the code:
Code: Select all
// select the specific database name we want to access.
$dbname=$dbusername."_".$dbname;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
so the problem must be somewhere in here:success in database connection.success in database selection.no table created.
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.";
}
?>try
Code: Select all
} else {
echo "no table created. ";
echo mysql_error();
}I don't see a call to mysql_connect().suthie wrote:// set your infomation.
$dbhost='localhost';
$dbusername='username';
$dbuserpass='mypassword';
$dbname='test';
// connect to the mysql database server.
echo "success in database connection.";
wow, that was dumb of me. looks like i accidentally took that out when i took out another line.
it works now!
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.";
}
?>