Jump to content

Recommended Posts

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?

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.

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.

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?

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.

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?

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());

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.