Jump to content

PHP 5.0 MySQL Error


GregL83

Recommended Posts

Hello,

 

I am having a weird problem with my webhost.  Originally I was running PHP 4.4.7 and MySQL.  I had my application actively running.  I then made the move to switch to OOP and needed to upgrade to PHP 5.  I called my webhost and told them that I need PHP 5.  They went ahead and enabled it.  They then informed me that I was recieving an error in my ctg-error log.  I can't fully remember the error but its was involving session_path line 0 and some othe warnings that didn't seem to affect my application.  They told me they would update a path in a system setting to fix the error.  After these two changes where made I went back to a previously functional application page and recieved a new error.

 

"Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in webpath/htdocs/locater.php on line 95"

 

I have simplified the code that recieves this error.  It is as follows:

<?php
...
query = "SELECT col3, col4 FROM samp WHERE col1 = 'test1' ORDER BY col3";
$result = mysql_query($query);
while(list($col3, $col4) = mysql_fetch_row($result)){
echo $col3;
echo $col4;
}
...
?>

 

I can't figure out why this does not work..... Please help!

Link to comment
Share on other sites

I added that line to my query and nothing changed...still the same errors.

 

I don't think this is a coding error.  The problem began after my webhost messed around with server settings.

 

Does anybody have any clue how to find the problem and solve it??  I have tested this method of getting variables from my MySQL database and get this error evertime.  It is very frustrating because it is only a few lines of code and I have two books and many tutorials saying the code is fine...

 

Please Help!!!

Link to comment
Share on other sites

<?php
$query = "SELECT col3, col4 FROM samp WHERE col1 = 'test1' ORDER BY col3";
$result = mysql_query($query) or die("Query 1 failed due to ".mysql_error());
while ($row = mysql_fetch_assoc($result) or die("Query failed due to ".mysql_error())){
$col3 = $row['col3'];
$col4 = $row['col4'];
}
echo $col3;
echo $col4;

added error checking. if the query is failing, it will tell you.

Link to comment
Share on other sites

@jonsjava: The way he used list() was fine.  He can change that back.

 

Now.  Check your MySQL connection.  It must be bad, which isn't letting the query go through.  Do me a favor.  What's the variable that you have your mysql_connect() assigned to? Do this:

 

if (is_resource($variable)) {

  echo "MySQL connection fine."

}

else {

  die ("FAILED. =[");

}

 

Use the right variable.

Link to comment
Share on other sites

Ok.....I think were on to something...which guru can solve this....

 

I get the error:

 

" Query failed: Table 'user_access.uinp' doesn't exist "

 

I think this has to do with the server settings.  Its weird though because this table is accessed for other functions...

Link to comment
Share on other sites

ok I ran the test and the mysql connection is fine...

 

I don't know how much that will help, because it is identical to the simplified version of this code.  Keep in mind that this application ran perfectly fine for a few months until my webhost made the changes indicated at the begining of this thread.  And the mystery is still not solved....thanks for you efforts so far though... I greatly appreciate it :)

 

see code below in next post

Link to comment
Share on other sites

hmm that code came out crappy..let me make it easier to read

 

<?php
function stringsize($string){
$limit = 12;
$str = $string;
if (strlen($str) > $limit){
	$str = substr($str, 0, $limit).'...';
}
return $str;	
}
$query = "SELECT nme, tp, r, vd, ovr, rr, enr, vr, ser, bnr FROM ".$_GET['st']." WHERE ct = '".$_GET['ct']."' ORDER BY nme";
$result = mysql_query($query) or die("Query failed: ".mysql_error());
while (list($name, $type, $rater, $vd, $overall, $ratio, $enter, $value, $service, $bnr) = mysql_fetch_row($result) or die("Query failed: ".mysql_error())){
echo "<tr><td><div class=\"ltr_scn\"><a href=\"scene.php?st=".$_GET['st']."&ct=".$_GET['ct']."&sc=$name\">$name</div></a></td><td><div class=\"ltr_scn\">$type</div></td><td><div class=\"ltr_scn\"><a href=\"\">";
$rater = stringsize($rater);
echo "$rater</div></a></td><td class=\"ltr_scn\">";
if($vd == "y"){
	echo "Yes";
}
else{
	echo "No";
}
?>

 

 

the rest of my code simply echo's the variables...

Link to comment
Share on other sites

I ran this function

<?php
$tables = mysql_query("SHOW TABLES FROM user_access;");
print_r($tables);
?>

 

All that printed was:

 

" Resource id #3 "

 

Also, I have other functioning pages using these tables.  I have verified using PHPMYADMIN that all the tables are still intact....

Link to comment
Share on other sites

I ran this function

<?php
$tables = mysql_query("SHOW TABLES FROM user_access;");
print_r($tables);
?>

 

All that printed was:

 

" Resource id #3 "

 

Also, I have other functioning pages using these tables.  I have verified using PHPMYADMIN that all the tables are still intact....

 

<?php

$tbl_query = mysql_query("SHOW TABLES FROM user_access");

while ($tables = mysql_fetch_array($tbl_query)) {

$table_result[] = $tables[0];

}

print_r($tables);

?>

 

That should do it.  Not sure how MySQL returns SHOW TABLES in php. >_>

Link to comment
Share on other sites

my results....

Array ( [0] => ak [Tables_in_user_access] => ak ) Array ( [0] => al [Tables_in_user_access] => al ) Array ( [0] => ar [Tables_in_user_access] => ar ) Array ( [0] => az [Tables_in_user_access] => az ) Array ( [0] => ca [Tables_in_user_access] => ca ) Array ( [0] => co [Tables_in_user_access] => co ) Array ( [0] => ct [Tables_in_user_access] => ct ) Array ( [0] => de [Tables_in_user_access] => de ) Array ( [0] => fl [Tables_in_user_access] => fl ) Array ( [0] => ga [Tables_in_user_access] => ga ) Array ( [0] => hi [Tables_in_user_access] => hi ) Array ( [0] => ia [Tables_in_user_access] => ia ) Array ( [0] => id [Tables_in_user_access] => id ) Array ( [0] => il [Tables_in_user_access] => il ) Array ( [0] => in [Tables_in_user_access] => in ) Array ( [0] => ks [Tables_in_user_access] => ks ) Array ( [0] => ky [Tables_in_user_access] => ky ) Array ( [0] => la [Tables_in_user_access] => la ) Array ( [0] => ma [Tables_in_user_access] => ma ) Array ( [0] => md [Tables_in_user_access] => md ) Array ( [0] => me [Tables_in_user_access] => me ) Array ( [0] => mi [Tables_in_user_access] => mi ) Array ( [0] => mn [Tables_in_user_access] => mn ) Array ( [0] => mo [Tables_in_user_access] => mo ) Array ( [0] => ms [Tables_in_user_access] => ms ) Array ( [0] => mt [Tables_in_user_access] => mt ) Array ( [0] => nc [Tables_in_user_access] => nc ) Array ( [0] => nd [Tables_in_user_access] => nd ) Array ( [0] => ne [Tables_in_user_access] => ne ) Array ( [0] => nh [Tables_in_user_access] => nh ) Array ( [0] => nj [Tables_in_user_access] => nj ) Array ( [0] => nm [Tables_in_user_access] => nm ) Array ( [0] => nv [Tables_in_user_access] => nv ) Array ( [0] => ny [Tables_in_user_access] => ny ) Array ( [0] => oh [Tables_in_user_access] => oh ) Array ( [0] => ok [Tables_in_user_access] => ok ) Array ( [0] => or [Tables_in_user_access] => or ) Array ( [0] => pa [Tables_in_user_access] => pa ) Array ( [0] => ri [Tables_in_user_access] => ri ) Array ( [0] => sc [Tables_in_user_access] => sc ) Array ( [0] => sd [Tables_in_user_access] => sd ) Array ( [0] => tn [Tables_in_user_access] => tn ) Array ( [0] => tx [Tables_in_user_access] => tx ) Array ( [0] => users [Tables_in_user_access] => users ) Array ( [0] => ut [Tables_in_user_access] => ut ) Array ( [0] => va [Tables_in_user_access] => va ) Array ( [0] => vt [Tables_in_user_access] => vt ) Array ( [0] => wa [Tables_in_user_access] => wa ) Array ( [0] => wi [Tables_in_user_access] => wi ) Array ( [0] => wv [Tables_in_user_access] => wv ) Array ( [0] => wy [Tables_in_user_access] => wy )

 

the $_GET['st'] variable is set to 'ma' and that should select from that table.  this page was correctly function before my webhost went and f'd it up

Link to comment
Share on other sites

cleaned up:

Array ( 
[0] => ak [Tables_in_user_access] => ak ) 
Array ( [0] => al [Tables_in_user_access] => al ) 
Array ( [0] => ar [Tables_in_user_access] => ar ) 
Array ( [0] => az [Tables_in_user_access] => az ) 
Array ( [0] => ca [Tables_in_user_access] => ca ) 
Array ( [0] => co [Tables_in_user_access] => co ) 
Array ( [0] => ct [Tables_in_user_access] => ct ) 
Array ( [0] => de [Tables_in_user_access] => de ) 
Array ( [0] => fl [Tables_in_user_access] => fl ) 
Array ( [0] => ga [Tables_in_user_access] => ga ) 
Array ( [0] => hi [Tables_in_user_access] => hi ) 
Array ( [0] => ia [Tables_in_user_access] => ia ) 
Array ( [0] => id [Tables_in_user_access] => id ) 
Array ( [0] => il [Tables_in_user_access] => il )
	Array ( [0] => in [Tables_in_user_access] => in ) 
	Array ( [0] => ks [Tables_in_user_access] => ks ) 
	Array ( [0] => ky [Tables_in_user_access] => ky ) 
	Array ( [0] => la [Tables_in_user_access] => la ) 
	Array ( [0] => ma [Tables_in_user_access] => ma ) 
	Array ( [0] => md [Tables_in_user_access] => md ) 
	Array ( [0] => me [Tables_in_user_access] => me ) 
	Array ( [0] => mi [Tables_in_user_access] => mi ) 
	Array ( [0] => mn [Tables_in_user_access] => mn ) 
	Array ( [0] => mo [Tables_in_user_access] => mo ) 
	Array ( [0] => ms [Tables_in_user_access] => ms ) 
	Array ( [0] => mt [Tables_in_user_access] => mt ) 
	Array ( [0] => nc [Tables_in_user_access] => nc ) 
	Array ( [0] => nd [Tables_in_user_access] => nd ) 
	Array ( [0] => ne [Tables_in_user_access] => ne ) 
	Array ( [0] => nh [Tables_in_user_access] => nh ) 
	Array ( [0] => nj [Tables_in_user_access] => nj ) 
	Array ( [0] => nm [Tables_in_user_access] => nm ) 
	Array ( [0] => nv [Tables_in_user_access] => nv ) 
	Array ( [0] => ny [Tables_in_user_access] => ny ) 
	Array ( [0] => oh [Tables_in_user_access] => oh ) 
	Array ( [0] => ok [Tables_in_user_access] => ok ) 
	Array ( [0] => or [Tables_in_user_access] => or ) 
	Array ( [0] => pa [Tables_in_user_access] => pa ) 
	Array ( [0] => ri [Tables_in_user_access] => ri ) 
	Array ( [0] => sc [Tables_in_user_access] => sc ) 
	Array ( [0] => sd [Tables_in_user_access] => sd ) 
	Array ( [0] => tn [Tables_in_user_access] => tn ) 
	Array ( [0] => tx [Tables_in_user_access] => tx ) 
	Array ( [0] => users [Tables_in_user_access] => users ) 
	Array ( [0] => ut [Tables_in_user_access] => ut ) 
	Array ( [0] => va [Tables_in_user_access] => va ) 
	Array ( [0] => vt [Tables_in_user_access] => vt ) 
	Array ( [0] => wa [Tables_in_user_access] => wa ) 
	Array ( [0] => wi [Tables_in_user_access] => wi ) 
	Array ( [0] => wv [Tables_in_user_access] => wv ) 
	Array ( [0] => wy [Tables_in_user_access] => wy )

the table you are querying does not appear to exist.

Link to comment
Share on other sites

It is table 'ma' and it exists according to all the other scripts and functions except this one.  sorry for posting the results like that.  I have no idea where .unip comes from.  I think its gotta be a setting of mysql, php.ini, or my web server...  I am stumped and enraged that my webhost continues to tell me it is a scripting error without properly reviewing the circumstances.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.