Need Assitance On Php & Mysql test.

Reply

Join Date: Sep 2008
Posts: 3
Reputation: Mr.Kazaam is an unknown quantity at this point 
Solved Threads: 0
Mr.Kazaam Mr.Kazaam is offline Offline
Newbie Poster

Need Assitance On Php & Mysql test.

 
0
  #1
Sep 21st, 2008
I was following this tut. on how to install Apache, PHP, Mysql, and PHPmyadmin. I need a bit of help! I get a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysql_test.php on line 15" everytime I test the mysql thing.

What ive done so far is :

Configuring PHP to work with MySQL:
Now that both PHP and MySQL are installed, we have to configure them to work together.

   1. Open up your php.ini file (C:/WINDOWS/php.ini) and find the line:

      ;extension=php_mysql.dll

      To enable the MySQL extension, delete the semi-colon at the beginning of that line.

   2. Next we must add the PHP directory to the Windows PATH. To do this, click: Start > My Computer > Properties > Advanced > Environment Variables. Under the second list (System Variables), there will be a variable called "Path". Select it and click "Edit". Add ";C:\php" to the very end of the string and click "OK".

   3. Restart your computer for the changes to take effect.

   4. Create a new file in your "htdocs" directory called "mysql_test.php".

   5. Copy the following code into "mysql_test.php" and click save. (Make sure to replace the MYSQL_PASS constant with the MySQL Password you specified during the MySQL installation).

      <?php

      # Define MySQL Settings
      define("MYSQL_HOST", "localhost");
      define("MYSQL_USER", "root");
      define("MYSQL_PASS", "password");
      define("MYSQL_DB", "test");

      $conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error());
      mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error());

      $sql = "SELECT * FROM test";
      $res = mysql_query($sql);

      while ($field = mysql_fetch_array($res))
      {
      $id = $field['id'];
      $name = $field['name'];

      echo 'ID: ' . $field['id'] . '<br />';
      echo 'Name: ' . $field['name'] . '<br /><br />';
      }

      ?>
   6. Open up Internet Explorer and type in "http://localhost/mysql_test.php". If the "mysql_test.php" page returns something similiar to:

      ID: 1
      Name: John

The author of the tutorial told me to write and save this in the htdocs.

  1. <?php
  2.  
  3. # Define MySQL Settings
  4. define("MYSQL_HOST", "localhost");
  5. define("MYSQL_USER", "root");
  6. define("MYSQL_PASS", "rashad");
  7. define("MYSQL_DB", "test");
  8.  
  9. $conn = mysql_connect("".MYSQL_HOST."", "".MYSQL_USER."", "".MYSQL_PASS."") or die(mysql_error());
  10. mysql_select_db("".MYSQL_DB."",$conn) or die(mysql_error());
  11.  
  12. $sql = "SELECT * FROM test";
  13. $res = mysql_query($sql);
  14.  
  15. while ($field = mysql_fetch_array($res))
  16. {
  17. $id = $field['id'];
  18. $name = $field['name'];
  19.  
  20. echo 'ID: ' . $field['id'] . '<br />';
  21. echo 'Name: ' . $field['name'] . '<br /><br />';
  22. }
  23.  
  24. ?>

replacing the " password " with my password?


The tutorial link is here : http://www.bicubica.com/apache-php-mysql/index.php
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Need Assitance On Php & Mysql test.

 
0
  #2
Sep 21st, 2008
Do you have a table called 'test' within the database 'test'?

change $res = mysql_query($sql); to $res = mysql_query($sql) or die(mysql_error());
Does this return an error?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: Mr.Kazaam is an unknown quantity at this point 
Solved Threads: 0
Mr.Kazaam Mr.Kazaam is offline Offline
Newbie Poster

Re: Need Assitance On Php & Mysql test.

 
0
  #3
Sep 21st, 2008
Yes. I have the test table. I did what the instructions said and did the use test; thing. Whenever I try the code you gave me, it says "Table 'test.test' doesn't exist"...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: Need Assitance On Php & Mysql test.

 
0
  #4
Sep 21st, 2008
can you use this code and let us know what it returns:
  1. <?php
  2.  
  3. mysql_connect("localhost","root","password");
  4.  
  5. $tables = mysql_list_tables("test");
  6.  
  7. while (list($table) = mysql_fetch_row($tables)) {
  8. echo "$table <br />";
  9. }
  10.  
  11. ?>
obviously change the password to your password.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 3
Reputation: Mr.Kazaam is an unknown quantity at this point 
Solved Threads: 0
Mr.Kazaam Mr.Kazaam is offline Offline
Newbie Poster

Re: Need Assitance On Php & Mysql test.

 
0
  #5
Sep 22nd, 2008
Okay I did as you said. In return I got " name ".
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: Riukeen is an unknown quantity at this point 
Solved Threads: 0
Riukeen Riukeen is offline Offline
Newbie Poster

Re: Need Assitance On Php & Mysql test.

 
0
  #6
Jan 27th, 2009
Hi Guys...


This is problem..

$sql = "SELECT * FROM test";


change table name .. "name" (=
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 60
Reputation: Andrieux is an unknown quantity at this point 
Solved Threads: 4
Andrieux Andrieux is offline Offline
Junior Poster in Training

Re: Need Assitance On Php & Mysql test.

 
0
  #7
Jan 27th, 2009
The problem is that your database is titled test, but the table inside that databse is named "name".

So when you use $sql = "SELECT * FROM test"; , it's trying to find the table "test" within the database that you connected to at the top of your file. (By the way, that's not a great way to connect to a database via PHP.
  1. //define variables
  2. $dbhost = "localhost";
  3. $dbuser = "andrieux";
  4. $dbpass = "pass";
  5. $dbdatabase = "andrieux";
  6.  
  7. //connect
  8. $db = mysql_connect($dbhost, $dbuser, $dbpass);
  9. mysql_select_db($db, $dbdatabase);

You don't need error fallbacks for something as simple as connecting to localhost, so you have alot of unneeded code.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: Riukeen is an unknown quantity at this point 
Solved Threads: 0
Riukeen Riukeen is offline Offline
Newbie Poster

Re: Need Assitance On Php & Mysql test.

 
0
  #8
Jan 27th, 2009
Originally Posted by Riukeen View Post
Hi Guys...


This is problem..

$sql = "SELECT * FROM test";


change table name .. "name" (=

$sql = "SELECT * FROM name";
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC