[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 402
  • Last Modified:

Database beginner here - PHP LANGUAGE USED MYSQL SOFTWARE USED - implemented DATABASE USING PHPMYADMIN WHEN I WROTE THE CODE IN PHP TO CALL THE DATABASE SO I CAN SEE THE OUTPUT OF THE DATABASE

Hello Techies out there. I am  stepping into a new area and I am very raw. It is database w/php and mysql . I am using phpmyadmin and dreamweaver to write the code (because its better for me cause its color coded and I see what certain tags do)

Uh, I created  a simple database called "NBA PLAYERS" with a table inside it called old_timers that table is then broken down into 5 groups which reflects the positions that are available ie. (shootingguards, pf, smallfowards, point guards and centers ) and I populated these tables with players I then saved the database and started to write a simple php file that I read from o'reilly php & mysql cookbook. I then upload the code onto my websites server but when I tyoed in the url of the page in my browser the page came back just a blank white page ( www.deanvlacich.com/test.php) no errors whatsoever , I know my hosting company supports php syntax because in the past I wrote small blocks of code and uploaded it and it worked. I really need to get this right. I am unemployed individual so I am trying to learn and understand as much things as possible I will include the code below as I said before no error messages were seen on screen can somebody help me out SOS. MAYDAY

<?

include 'db.inc';


?>
<!DOCTYPE HTML PUBLIC
               "-//W3C//DTD HTML 4.0 Transitional//EN"
               "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>TEST</title>
</head>
<body><pre>
<?php
   
   $connection = mysql_connect("localhost");

   mysql_select_db("NBA PLAYERS", $connection);

   // (2) Run the query on the winestore through the
   //  connection
   $result = mysql_query ("SELECT * Shootguards, Point Guards, Snall Fowards , Power Forwards , Centers FROM old_timers WHERE 1 ORDER BY Snall Fowards ASC LIMIT 0, 30', $connection");

   // (3) While there are still rows in the result set,
   // fetch the current row into the array $row
   while ($row = mysql_fetch_row($result))
   {
     // (4) Print out each element in $row, that is,
     // print the values of the attributes
     for ($i=0; $i<mysql_num_fields($result); $i++)
       echo $row[$i] . " ";

     // Print a carriage return to neaten the output
     echo "\n";
   }
   // (5) Close the database connection
   mysql_close($connection);
?>
</pre>
</body>
</html>  
0
dean3740
Asked:
dean3740
1 Solution
 
Alf666Commented:
Your mysql_connect line should include your mysql username and password :

   $connection = mysql_connect("localhost", "your_username", "your_password");

0
 
dean3740Author Commented:
even if i served from my webserver from my hosting company? do you my username and password defined by sql? i tried that still white blank page,

0
 
Alf666Commented:
You must have a username/password combination allowed to talke to your MySQL.

Can I suggest the following code ? :

$db_selected = mysql_select_db("NBA PLAYERS", $connection);

if (!$db_selected) {
   die ('Can\'t use db : ' . mysql_error());
}

This should give you much more verbose debug.

0
 
madwaxCommented:
If you want you can read my article on using mysql with php through a db-connection class that handles everything with connection, databasechoosing etc:

http://www.ivtaco.se/articles/article.php?articleID=1

//jan


0
 
smphilCommented:
Try changing your script to this you should get the errors then! I added it in allready just cut and pastes it! Hope it works

("SELECT * Shootguards, Point Guards, Snall Fowards , Power Forwards , Centers FROM old_timers WHERE 1 ORDER BY Snall Fowards ASC LIMIT 0, 30', $connection")or die(mysql_error());
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now