Yesterday some of the guys helped me out with some php include issues that were happening when migrating to php5 here: http://forums.digitalpoint.com/showthread.php?t=625008 I decided that rewriting my variables in the code was the best thing to do to avoid future issues. Once I solved this problem, a completely different problem poped up when running some standard SQL queries. I have two different database based scripts that work perfectly in PHP4, but as soon as I switch it over to PHP5, one of them all of a sudden finds no values in the database and the other gives the following error: mysql_num_rows(): supplied argument is not a valid MySQL result resource Again, no changes in the code...it works perfect in PHP4 but doesn't work on PHP5. Any ideas on issues with SQL compatibility between PHP4 and 5, or any other ideas of why this wouldn't work when migrating? Below is a rough view of some of the code that I edited down to show the main structure. Thanks in advance! <?php require_once("config.php"); $sql_query = "SELECT * FROM database WHERE `primary` = '".$id."'"; $result = mysql_query($sql_query); if(mysql_num_rows($result)) { while($row = mysql_fetch_row($result)) { print ("$row[0]"); } } else { echo "no values in the database"; } ?> Code (markup):
Are those query run after a form is processed? I mean, does it depend on data entered by visitors? If so, you have 2 choices : 1 - rewrite all variables that come from forms like this : $var becomes $_GET['var'] or $_POST['var'] , the choice depends on the method property used on the html form. 2 - Set the register_globals to ON in the php config file (php.ini), but this is a bad choise, even PHP will not allow you to use this technique anymore in PHP 6.
No. The query is run based on a URL passed variable. For example, script.php?id=whatever, and it uses id as a sort.
i think it's your register_global setting, it's by default ON on php 4 and OFF on php5 since it will be removed on php6, you should start changing your code. change all variable you get from a url like script.php?id=whatever from mere $id to $_GET['id'] watch out form post / get variable, don't get them mixed up.
So your variable are stored on the $_GET array, $_GET['id']=watever; My first reply is still valid as url based variable are stored in the $_GET array if the register_globals is On, if it's Off these variable are stored in the same name in the url ($id=variable).
instead of us guessing what the problem is, you can basically debug it a bit yourself <?php require_once("config.php"); echo $id;// where does this come from $_GET or $_POST ? $sql_query = "SELECT * FROM database WHERE `primary` = '".$id."'"; $result = mysql_query($sql_query) OR die(mysql_error());// show an error if(mysql_num_rows($result) > 0 ) // are there more then 0 results { while($row = mysql_fetch_row($result)) { print ("$row[0]"); } } else { echo "no values in the database"; } ?>
i thought hen register global is ON, all passed variable will be available as their name? so it's reverse of hat you say. CMIIW