Supplied Arguments Not Valid

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jaxamercy
Forum Newbie
Posts: 6
Joined: Sun Jul 01, 2007 1:31 pm

Supplied Arguments Not Valid

Post by Jaxamercy »

Hi All

I hope someone can help. A little background..

I designed my site using PHP5 usining mysqli extentions enabled. All was fine until I came to host it where I found out the host I'm with does not have mysqli extentions enalbed and wont enalbe them. Therefore I've been tasked with redoing everything using mysql extentions. Heres what I've done....

I semi coloned the " extension=php_mysqli.dll" in my php.ini and removed the semi colon from "extension=php_mysql.dll"

I then set about changing the occurances of mysqli in my code and replaced it with mysql. Needless to say this didn't work. This throws up errors when I simply try to select all records from my database and show them in my page. The code below is basically how I select records and display them.


Code: Select all

<?php


$cxn = mysql_connect('localhost','root','password','database')
         or die ("couldn't connect to server");

$query="SELECT * FROM table ORDER BY postdate DESC ";
$result=mysql_query($cxn,$query);

echo "<table align='center' cellpadding='5' border='0'>";
$counter=1;                                          
  while($row = mysql_fetch_assoc($result))            
  {
     extract($row);                                    
     echo "<tr><td valign='center' width='5%' align='left'
                   style='font-weight: bold; 
                   font-size: 1.2em'\n>";
     
     if( $counter == 1 )                               
     {
     }
     echo "field1</td>"; 
     echo "<td>field2</td>";                  
     echo "<td>field3</td>";              
     $counter++;                                       
  }
echo "</table>";


?>
When I run this code the following errors are shown

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\PoppedLung\test.php on line 8

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\PoppedLung\test.php on line 12

I can tell that something is wrong with the way I execute the query but can't tell what?

Any help greatly appreciated!!

Thanks

Jax[/quote]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The query to perform is the first parameter to mysql_query(), not the second. Also, mysql_connect() doesn't have a "database" parameter.
Jaxamercy
Forum Newbie
Posts: 6
Joined: Sun Jul 01, 2007 1:31 pm

Post by Jaxamercy »

Great thanks for this

Just one further question if I may, How do I instruct which databse to perform actions on?

Thanks again
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Jaxamercy
Forum Newbie
Posts: 6
Joined: Sun Jul 01, 2007 1:31 pm

Post by Jaxamercy »

This has solved my problems,

Thank you very much for your help!!!!
Post Reply