Jump to content
Sign in to follow this  
dph1077

Php Mysql Help

Recommended Posts

Any help is greatly appreciated. The situation is this:

 

In control panel, I created a MySQL database. Using the PHPMyAdmin, I

populated the database with 2 entries (just for starters). I even have added

a user and password to the database. Using the info that the site gives to

connect and some from other sites, this is the code snipet I am using trying

to connect to the database and display its contents on the screen. Oh, the link

to the page is http://www.areacode860.com/data.php , the database name,

user name, and password are all "pumpedup" without the quotes.

 

<?php

// connect to the database server

$dbcnx = @mysql_connect('localhost', 'areacod_pumpedup', 'areacod_pumpedup');

if (!$dbcnx){

exit('<p>Unable to connect to the database server, check root & password in code.</p>');

}

 

// select info from the database

if (!@mysql_select_db('areacod_pumpedup')) {

exit ('<p>Unable to locate database in system. Check name in code.</p>');

}

 

?>

 

<p>Here are all the products in our database:</p>

 

<?php

 

//request all products from database

$result = @mysql_query('SELECT * FROM tblproducts');

if (!$result) {

exit('<p> Error performing query: ' . mysql_error() . '</p>');

}

 

// display the info from the database

while ($row = mysql_fetch_array($result)) {

echo '<p>' . $row['item'] . '</p>';

}

?>

 

 

I have connected to databases in the past using ASP so I'm not entirely new

to this, just to using PHP & MySQL. Again, any and all help is greatly appreciated!

Share this post


Link to post
Share on other sites

Well, I would say it's the apostrophes in the $row['item'] because they will make the PHP try to echo things out. Try taking them out and see if it works. It's been a while since I got to mess with PHP code, though, so someone may have better advice.

 

Are you getting any specific error? Blank page? Partial text?

Share this post


Link to post
Share on other sites

As seen with the code, I have little error traps for each step. I can't

even get past the first step, connecting to the database! LOL

My guess is the part about the password is tripping me up. I don't think

passwords were created when I made this in PHPMyAdmin. The page just shows the error trap message.

Share this post


Link to post
Share on other sites

Ok... in MySQL after you created the database and then created a user and password, did you actually add that user/password to your database? I sometimes forget to do that bit.

 

Also, your password won't have your areacod_ prefix in front of it--just the user name and database get that automatically.

Share this post


Link to post
Share on other sites

Owatagal, thanks for your help, it works now. The password is what

appears to have been stopping me! Once I took the "areacod_" part

off of it, it is working now!

 

Now I'll just have to play with the sql query part after I make the db

bigger to learn to pare out the info that I want. Thanks again!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...