Darkmatter5 Posted August 14, 2008 Share Posted August 14, 2008 Here's my code <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT * FROM jobs WHERE job_number = $job"; $result=mysql_query($query); $row=mysql_fetch_array($result); include 'library/closedb.php'; ?> and <?php $byrndb->client_list(2,$row['client_id']); ?> My error isn't in the function in the second code, but in the line of "$row=mysql_fetch_array($result);" The error says "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\byrndb\neweditjob.php on line 60" Also the reason why I included the function is because I wanted to know if I reference the result of $row['client_id'] correctly in the parameters of the function? Basically is the syntax correct? Can anyone tell me what might be causing this error? Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/ Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 Normally with that error it means there was a problem with your query, you can find out whether this true or not by changing $result=mysql_query($query); to $result=mysql_query($query) or die($query . '<br >'.mysql_error()); Also I cannot see how $byrndb->client_list(2,$row['client_id']); has any reference with the code you posted. Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616428 Share on other sites More sharing options...
Darkmatter5 Posted August 14, 2008 Author Share Posted August 14, 2008 Both sets of code are in the same page. Basically how can I pass the value of $row['client_id'] as a parameter in the function call? Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616443 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 Both sets of code are in the same page. Basically how can I pass the value of $row['client_id'] as a parameter in the function call? The way you're doing is the correct to pass parameters to a function/method. Just make sure your client_list method accepts two parameters. Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616448 Share on other sites More sharing options...
Darkmatter5 Posted August 14, 2008 Author Share Posted August 14, 2008 The function does support 2 parameters. I ran a test to simply echo the result of $row with the following code. <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT * FROM byrnjobdb.jobs WHERE job_number = $job"; $result=mysql_query($query) or die($query . '<br >'.mysql_error()); $row=mysql_fetch_array($result); echo "Job_number: " .$row['job_number']; include 'library/closedb.php'; ?> It only outputs "Job_number: ". If I use Navicat and run the same query, job_number has the value of 4695. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616464 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 I am not understanding your code, is the following <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT * FROM byrnjobdb.jobs WHERE job_number = $job"; $result=mysql_query($query) or die($query . '<br >'.mysql_error()); $row=mysql_fetch_array($result); echo "Job_number: " .$row['job_number']; include 'library/closedb.php'; ?> part of your client_list() function? It would be helpful if you posted the function in full. Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616484 Share on other sites More sharing options...
Darkmatter5 Posted August 14, 2008 Author Share Posted August 14, 2008 Oh. Well my first post had two questions. One concerning the query code and the other concerning the function parameter syntax. You answered the parameter syntax question so in this new post I just did I didn't include the function code as it theoretically works as long and the query code works. So I just included the query code. I'm currently trying to figure out why my query code isn't getting a result from the query when I know there should be a result in $row['job_number'] of "00001". So why might the code of <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT * FROM byrnjobdb.jobs WHERE job_number = $job"; $result=mysql_query($query) or die($query . '<br >'.mysql_error()); $row=mysql_fetch_array($result); echo "Job_number: " .$row['job_number']; include 'library/closedb.php'; ?> not create an output of "Job_number: 00001". When I know for a fact that the record has that as job_number in the table. How might I output all the contents of $row to see if it got anything at all? Or do you have any other ideas on troubleshooting if $row is getting anything? Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616492 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 Judging from what you posted this has nothing to do with the client_list() function. If thats the case where is the $job variable assigned? Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616496 Share on other sites More sharing options...
Darkmatter5 Posted August 14, 2008 Author Share Posted August 14, 2008 The job variable is assigned via a dropdown list earlier in the page, sorry I didn't say that earlier. So assuming $job has a valid value, why might this not be working? Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616508 Share on other sites More sharing options...
wildteen88 Posted August 14, 2008 Share Posted August 14, 2008 Where is the line this variables gets assigned? You might want to echo your query to see how its formatted, eg query="SELECT * FROM byrnjobdb.jobs WHERE job_number = $job"; echo '<pre>' . htmlentities($query) . '</pre>'; $result=mysql_query($query) or die($query . '<br >'.mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616513 Share on other sites More sharing options...
Darkmatter5 Posted August 14, 2008 Author Share Posted August 14, 2008 It definitely helped!! In: query="SELECT * FROM byrnjobdb.jobs WHERE job_number = $job"; it was suppose to be job_id, not job_number. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119652-help-with-mysql_fetch_array-result-and-error-message/#findComment-616580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.