The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Basic PHP help, can't execute query

zen-zen- Registered User regular
edited September 2010 in Help / Advice Forum
Hi all, basically this is my first time trying to make a PHP site from scratch, and using my own local server (WAMP server) after having a couple of lectures on it in school.

Now I'm trying to recreate the site I have on the schools local server, however I'm falling down at the first hurdle.

I have a table of albums with only one record in it (for now, just until I get this working).

tablew.jpg

I have set up a connection to the server using a page I've called conninfo.php
<?php
$strServer="localhost";
$strDatabase="albumdrop";
$strUser="root";
$strPwd="mike";

$strDB=mysql_connect($strServer,$strUser,$strPwd)or die("Could not open database");
$database=mysql_select_db("strDatabase",$strDB);

?>

And here is what I'm trying to do:
<?php include("conninfo.php");

$query="SELECT * FROM albums";

$result = mysql_query($query) or die ("didnt work");

while($r=mysql_fetch_array($result))
{
echo $r["artist"];

echo "<br>";
}

?>

But of course I keep getting the or die 'didn't work' message.

So H/A, any ideas? Or should I take this to Moe's technology tavern?

zen- on

Posts

  • CircaCirca Registered User regular
    edited September 2010
    $database=mysql_select_db("strDatabase",$strDB);

    -

    Is your database named "strDatabase" or did you perhaps omit a dollar sign?

    Circa on
  • zen-zen- Registered User regular
    edited September 2010
    Man, that was fast. I feel like an absolute toolbox for getting stuck on that for so long.

    Thanks, Circa. I'm sending you as much internet love as I can, right now.

    zen- on
  • BlochWaveBlochWave Registered User regular
    edited September 2010
    I'm no php expert, only things I can think of are the variable names like the guy said, and the obvious question of whether albums is actually the table name.

    edit: aww I got beat :(

    BlochWave on
  • zen-zen- Registered User regular
    edited September 2010
    Yeah everything works now :D

    I guess I need to be more careful with syntax.

    zen- on
Sign In or Register to comment.