Php Mysql Help

Any help is greatly appreciated. The situation is this:<br /><br />In control panel, I created a MySQL database. Using the PHPMyAdmin, I<br />populated the database with 2 entries (just for starters). I even have added<br />a user and password to the database. Using the info that the site gives to <br />connect and some from other sites, this is the code snipet I am using trying<br />to connect to the database and display its contents on the screen. Oh, the link<br />to the page is <a href="http://www.areacode860.com/data.php" target="_blank">http://www.areacode860.com/data.php</a> , the database name,<br />user name, and password are all "pumpedup" without the quotes. <br /><br /><?php<br />// connect to the database server<br />$dbcnx = @mysql_connect('localhost', 'areacod_pumpedup', 'areacod_pumpedup');<br />if (!$dbcnx){<br /> exit('<p>Unable to connect to the database server, check root & password in code.</p>');<br /> }<br /><br />// select info from the database<br />if (!@mysql_select_db('areacod_pumpedup')) {<br /> exit ('<p>Unable to locate database in system. Check name in code.</p>');<br /> }<br /><br />?><br /><br /><p>Here are all the products in our database:</p><br /><br /><?php<br /><br />//request all products from database<br />$result = @mysql_query('SELECT * FROM tblproducts');<br />if (!$result) {<br /> exit('<p> Error performing query: ' . mysql_error() . '</p>');<br /> }<br /><br />// display the info from the database<br />while ($row = mysql_fetch_array($result)) {<br /> echo '<p>' . $row['item'] . '</p>';<br /> }<br />?><br /><br /><br />I have connected to databases in the past using ASP so I'm not entirely new<br />to this, just to using PHP & MySQL. Again, any and all help is greatly appreciated!<!--content-->
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.<br /><br />Are you getting any specific error? Blank page? Partial text?<!--content-->
As seen with the code, I have little error traps for each step. I can't<br />even get past the first step, connecting to the database! LOL<br />My guess is the part about the password is tripping me up. I don't think<br />passwords were created when I made this in PHPMyAdmin. The page just shows the error trap message.<!--content-->
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.<br /><br />Also, your password won't have your areacod_ prefix in front of it--just the user name and database get that automatically.<!--content-->
Owatagal, thanks for your help, it works now. The password is what<br />appears to have been stopping me! Once I took the "areacod_" part<br />off of it, it is working now! <br /><br />Now I'll just have to play with the sql query part after I make the db<br />bigger to learn to pare out the info that I want. Thanks again!<!--content-->
No problem... glad it worked!<!--content-->
 
Back
Top