Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call to Undefined error 1

Status
Not open for further replies.

samflex

IS-IT--Management
Jun 28, 2004
45
US
I have been struggling with this code now for a couple of days and was wondering if anyone can please assist me with it.

I have a form that has a link called Details.
If you click on the Details link, it will invoke this script and display the details of the records based on the id being passed to it.

So far, only id is being displayed, nothing else.

After scouring the internet for several days, I found an article that says that to do what I am trying to do, which is to display values for the rest of the fields, I needed to do a for loop.

Being so new at php, ( I am more of a vb programmer), I am having problem making the loop work for me.
Can someone kindly help me, please?

here is the entire code and thanks in advnce.

Code:
<?php
$conn = odbc_connect("counts", "", "") or die(odbc_error());
$cur = "SELECT fctrafic.id,fctrafic.location, fctrafic.location2,fctrafic.distance, fctrafic.direction,trafficCountsFiles.contentType, trafficCountsFiles.FileData FROM trafficCountsFiles,fctrafic where fctrafic.id = trafficcountsFiles.sitecode and fctrafic.id = '".$_GET["id"]."'";
$result=odbc_exec($conn,$cur);
$res = $cur->fetch();
for ($i=0; $i<12; $i++) {
	$cn = strtoupper($cur->ColumnName($i));
	$$cn = $cur->GetColumn($i);
	$cv = $$cn;
}
echo "  <div align=\"center\">
 <table cellpadding='2' cellspacing='2'>
<td class='header'><font size='-3'>ID</font></td><td class='name'><font size='-3'>" . ((isset($id)) ? $id: 'No ID Found') . "</font></td><td class='header'><font size='-3'> TYPE</font></td><td class='name'><font size='-3'>" . ((isset($types)) ? $types : 'Type Not Available') . "</font></td></tr>
<td class='header'><font size='-3'>AADT</font></td><td class='name'><font size='-3'>" . ((isset($aadt)) ? $aadt : 'No Record Found') . "</font></td><td class='header'><font size='-3'> DATE</font></td><td class='name'><font size='-3'>" . ((isset($fdate)) ? $fdate : 'No Date Available') . "</font></td></tr>
<tr><td class='header'><font size='-3'>LOCATION</font></td><td class='name'><font size='-3'>" . ((isset($location)) ? $location : 'No Record Found') . "</font></td><td class='header'><font size='-3'>DISTANCE</font></td><td class='name'><font size='-3'>" . ((isset($distance)) ? $distance : 'No Record Found') . "</font></td></tr>
<tr><td class='header'><font size='-3'>REF LOCATION</font></td><td class='name'><font size='-3'>" . ((isset($location)) ? $location : 'No Record Found') . "</font></td><td class='header'><font size='-3'>DIRECTION</font></td><td class='name'><font size='-3'>" . ((isset($direction)) ? $direction : 'No Record Found') . "</font></td></tr>
<tr><td class='header'><font size='-3'>FILE NAME</font></td><td class='name'><font size='-3'>" . ((isset($files)) ? $files : 'No File(s) Found') . "</font></td></tr>
</table><br>
<button name=\"close\" value=\"Close\" onClick='window.close()'>Close</button>
</div>";
?>
</body>
</html>
 
I am confused. Your post is titled "Call to undefined error". However, you do not mention any such error message within your post. Please make quor question clearer - is it about the error message or trouble with a loop? If an error message is displayed please give details when, which line, and what the code is.
Cheers.
 
My apology.

What I wanted to say was that if I remove the loop, the code does not error out, although only id is displayed; the rest of the fields are blank even though there are records in the database.

However, after what I have read, I believe the loop I included would help populate the form variables but the loop is causing the call to underfined error.

Here is the specific error message:

Fatal error: Call to a member function on a non-object

and it sometimes points to this line:

Code:
$conn = odbc_connect("counts", "", "") or die(odbc_error());

or this line:


Code:
$cur = "SELECT fctrafic.id,fctrafic.location, fctrafic.location2,fctrafic.distance, fctrafic.direction,trafficCountsFiles.contentType, trafficCountsFiles.FileData FROM trafficCountsFiles,fctrafic where fctrafic.id = trafficcountsFiles.sitecode and fctrafic.id = '".$_GET["id"]."'";

But from what I have read so far, even though it points to those lines, those lines are not necessarily the culprits.

And as stated, without the loops, the html table displays the fields but only id has value; the rest have none.
So, although my php knowledge is next to zero right now, I am reasonably sure that the loop is the source of my problem.

Thanks for your inquiry.
 
what sort of database are u accessing is it a M Access database
 
Yes, it is ms Access, thanks for asking.
 
Finding it difficult to see what is happening in this script but could this be an error
Code:
$$cn = $cur->GetColumn($i);
$cv = $$cn;
ie $$
 
I have made a lot of changes to this but still getting some errors on line 53 which is here:

</tr>, just before the </table> tag.

I am frustrated by this.

Code:
<?php
$conn = odbc_connect("counts", "", "") or die(odbc_error());
$sql = <<< END_SQL
SELECT
     fctrafic.site_code,
     fctrafic.location,
     fctrafic.location2,
     fctrafic.distance,
     fctrafic.direction
     trafficcountsFiles.fdate,
     trafficcountsFiles.types,
     trafficcountsFiles.aadt,
     trafficcountsFiles.filename
FROM
     trafficCountsFiles,
     fctrafic
WHERE
     fctrafic.site_Code = trafficcountsFiles.sitecode AND
     fctrafic.site_Code = "{$_GET["site_Code"]}";
END_SQL;
$results = odbc_exec($conn,$sSQL);
while($row = odbc_fetch_array($results))
     {
     echo <<< END_HTML
<div align="center">
     <table cellpadding="2" cellspacing="2">
          <tr>
               <td class="header"><font size="-3">SITE CODE</font></td>
               <td class="name"><font size="-3">$site_Code</font></td>
               <td class="header"><font size="-3"> TYPE</font></td>
               <td class="name"><font size="-3">$types</font></td>
          </tr>
          <tr>
               <td class="header"><font size="-3">AADT</font></td>
               <td class="name"><font size="-3">$aadt</font></td>
               <td class="header"><font size="-3"> DATE</font></td>
               <td class="name"><font size="-3">$fdate</font></td>
          </tr>
          <tr>
               <td class="header"><font size="-3">LOCATION</font></td>
               <td class="name"><font size="-3">$location</font></td>
               <td class="header"><font size="-3">DISTANCE</font></td>
               <td class="name"><font size="-3">$distance</font></td>
          </tr>
          <tr>
               <td class="header"><font size="-3">REF LOCATION</font></td>
               <td class="name"><font size="-3">$location2</font></td>
               <td class="header"><font size="-3">DIRECTION</font></td>
               <td class="name"><font size="-3">$direction</font></td>
          </tr>
          <tr>
               <td class="header"><font size="-3">FILE NAME</font></td>
               <td class="name"><font size="-3">$filename</font></td>
       </tr>
     </table>
     <br>
     <button name="close" value="Close" onClick="window.close()">Close</button>
</div>
END_HTML;

?>
 
you didn't close the "while" loop... could it be the problem?

while($row = odbc_fetch_array($results))
{
echo <<< END_HTML
<div align="center">
...
...
</div>
END_HTML;

?>

there is no "}" after END_HTML;
 
Hiya,
if closing the loop does not work
(if you indent everything properly it would be easier to spot these errors) maybe some default error checking will help?

Echo/print your query and check if everything is ok. Check for spellingmistakes whilst you are on it.

Next check the $result set and echo/print an error message when it is empty.

I assume that your id is displayed because it is taken from the $_GET and not from the query.

Also check that your db connection is really made.

Maybe even output only one row/field with a command similar to mysql_result($result, $i, "title").

Good luck

JR
(In need of a cool signature)
 
Chacalinc,
I have already closed the loop and still getting the error.

JR,

in asp , you would response.write $conn to display the connection and you would response.end to ensure that code stops after testing connection.

How do you do that in php.

I mean, I could say:
echo $conn but the error message is still there.
So there is got to be a way to say test connection only and stop further code processing.

As I said before, what made it easier for me to learn asp is there are so many resources and so many people willing to take the code and test on their machines to help detect bugs.

I haven't seen that so far on php since I started working on the dreaded code since last week.

I am not knocking on anyone at all so please don't take offense at my comment.
I am just saying that someone here tried to persuade me into abandoning asp for php because according to him, you get more help with php than asp.
Since I got plenty of help with asp, I couldn't wait to jump into php.

This has frustrated me beyond anything I have done as a programmer.
 
Question to the forum moderator!!!!
Can we somehow exchange email addresses without publishing them in the thread?

OK, on this issue.. I need to take my book, cause I am just a starter at this most fantastic language :)

But maybe start by doing echo for the query itself.
If no one else has jumped in by the time I get back home I will tell you how to do some basic checks on the db connection.

I believe that you usually use an if(!$conn)
echo "big problem";

also try echo $sql

I see that in the $results = odbc_exec($conn,$sSQL);
you have $sSQL . Maybe this is something I am unware of or should it be $sql the same as the query?

JR
(In need of a cool signature)
 
JR,
Thanks for your concern.
I spotted that earlier and changed it to $sql but still the same error problem.
 
And what is the result of the echo's?
especially the echo $sql; ?

JR
(In need of a cool signature)
 
I am back to the same point I made in my 2 posts ago.
In that post, I indicated that in asp,
you would response.write $sql then response.end

This way, only thing that gets processed is the sql statement and processing stops after that.

So even after I echo $sql, as long as there is no mechanism for stopping the processing after echoeing, the entire code will be processed along with the echo statement and as a result, the same error will continue to be thrown and the intent of echoing is defeated.
 
oh ok.
so why not simply echo the bit you wish, but make a new test.php file and just copy the connection and the query in there and run that.

It will simply stop after the echo. and you can check if your query is fine.

If so just try to display only 1 field from then database from only 1 row. If that works you know for sure that your connection is fine and your query is fine.

Back to the basics...
or do I miss something?

JR
(In need of a cool signature)
 
Here is what I got so far.

If I test only the connection:
Code:
<?php
$conn = odbc_connect("counts", "", "") or die(odbc_error());
echo $conn;
?>
I get this:

Resource id #1

What does that mean?

If I run the connection and the sql statement like this:
Code:
<?php
$conn = odbc_connect("counts", "", "") or die(odbc_error());
$sql = <<<END_SQL
SELECT
     fctrafic.site_code,
     fctrafic.location,
     fctrafic.location2,
     fctrafic.distance,
     fctrafic.direction,
     trafficcountsFiles.fdate,
     trafficcountsFiles.types,
     trafficcountsFiles.aadt,
     trafficcountsFiles.filename
FROM trafficCountsFiles,fctrafic
WHERE fctrafic.site_Code = trafficcountsFiles.sitecode
AND fctrafic.site_Code = "{$_GET['site_Code']}";
END_SQL;
echo $sql;
I get this error:

Parse error: parse error, unexpected $end in e:\inetpub\ on line 13

Line 13 is here ==> trafficcountsFiles.filename

Even if I run the sql statement without the connection beginning with this;

$sql = <<<END_SQL

and ending with this:

$sql = <<<END_SQL

I still get error on line 13
 
?> might help at the end of the file

JR
(In need of a cool signature)
 
?> was there on my code and during individual tests; I just forgot to iclude it on that one I posted.
 
Ok, I am not familiar with what <<<END_SQL does, but it look s impressive. However try the following

Code:
<?php
$conn = odbc_connect("counts", "", "") or die(odbc_error());
$sql = "SELECT
     fctrafic.site_code,
     fctrafic.location,
     fctrafic.location2,
     fctrafic.distance,
     fctrafic.direction,
     trafficcountsFiles.fdate,
     trafficcountsFiles.types,
     trafficcountsFiles.aadt,
     trafficcountsFiles.filename
FROM trafficCountsFiles,fctrafic
WHERE fctrafic.site_Code = trafficcountsFiles.sitecode
AND fctrafic.site_Code = ".{$_GET['site_Code']};

echo $sql;

?>

and let me know what happened?

JR
(In need of a cool signature)
 
trafficcountsFiles.filename
FROM trafficCountsFiles,

See the C in the from clause and c in the above?

Might be case sensitive

JR
(In need of a cool signature)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top