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

suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

nothing works... host problem? *solved*

Post by suthie »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to do a user login system just as a test with justfree.com....

nothing i do works. I have resorted to literally copying and pasting stuff i googles and just putting in my info. i can't get the mysql database to work... is it a host problem? or something dumb i am overlooking?

here is one of the scripts i tried using that didn't work

Code: Select all

<?

/**
 * Connect to the mysql database.
 */
$conn = mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db('penguinflash_vibe', $conn) or die(mysql_error());

CREATE TABLE users (
    username varchar(30),
    password varchar(32));


?>

i did that and then went to the php myadmin thing and there was no table in the database. what is the issue?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]


edit:
here is the code that made it work:

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.";
}

?>
Last edited by suthie on Sun Jun 10, 2007 7:53 am, edited 2 times in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Are any errors coming up?
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

no

its just a blank screen
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, let's fix the syntax error then.

Run this, will ya?

Code: Select all

<?php

error_reporting(E_ALL);

/**
* Connect to the mysql database.
*/
$conn = mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db('penguinflash_vibe', $conn) or die(mysql_error());

$sql = 'CREATE TABLE users (
username varchar(30),
password varchar(32));';


?>
Tell me what you get.
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

the same thing happens...

i get a blank screen and there is still no table in the database.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The code posted so far creates no output nor does it call any functions that would make the SQL run at the database. It should be a nicely blank screen.
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

very true....

okay so now i ran this:

Code: Select all

<?php

// set your infomation.
$dbhost='localhost';
$dbusername='username';
$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.
$dbname=$dbusername."_".$dbname;
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.";
}

?>
and got this:
success in database connection.Access denied for user 'penguinflash_admin'@'localhost' to database 'penguinflash_admin_users'

why would it deny me access? i know the user and password i put in are right because i used them to check if the table had been created in php myadmin
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

does your database user has all the privileges?
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

yes. the user has every privilege possible.

is it wrong to leave the host at "localhost"? should that be the name of the website or something?
.Stealth
Forum Commoner
Posts: 57
Joined: Wed Jan 10, 2007 12:15 pm
Location: Manchester, England

Post by .Stealth »

looks like you are not allowed to create tables with your priveleges which is abit stupid
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

yeah that is really stupid if it is the case. its not like im a user on somebody else's site. this is supposed to be my account on justfree.com

is there another possibility?

ive created a table from within php myadmin before and it worked there... but then when i tried to use that table i couldnt put data in or take it out. (thats why im trying to create a table with straight php code now)
.Stealth
Forum Commoner
Posts: 57
Joined: Wed Jan 10, 2007 12:15 pm
Location: Manchester, England

Post by .Stealth »

suthie wrote:yes. the user has every privilege possible.

is it wrong to leave the host at "localhost"? should that be the name of the website or something?

didnt they give you any details?
localhost might be a different database your trying to connect to.

you will probably need a url as the database might not be hosted on the local host.
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

I just found a justfree.com "how to make a website" tutorial. it says that "localhost" is correct. now what?
Last edited by suthie on Sat Jun 09, 2007 5:14 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:they never gave me any details... what might it be?

i tried using "justfree" also.

i searched the FAQ and found nothing.
could be anything.

mysql1.example.com

check your emails.
suthie
Forum Commoner
Posts: 68
Joined: Sat Jun 09, 2007 10:46 am

Post by suthie »

I just verified that "localhost" is correct. (sorry i edited the old post instead of posting a new one)

what other possibilities are there?
Post Reply