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>
 
Bingo!

After removing the {} from the .GET part, the sql statement came out perfect.

In other words, when I used this:

[cde]
<?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;

?>
[/code]

I got the sql statement working.

Now, can you help change the rest, please?

Can you help tie all together with this part:


Code:
$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;

?>

For someone who is just starting out new in this lanaguage, you have done very well.

Thank you!
I will try and see if I can tie them together myself too.
 
The {} I indeed overlooked. the ". before the $_GET was required, otherwise it thinks it is just text.

$results = odbc_exec($conn,$sSQL); may need to change into just $sql

How did the echo come out for the sql query? Did it look ok?

Maybe try in your test script:
$location = odbc_result($results, 0, 'location'))

and
echo $location;

did this give a location?

Then when that works look again at
while($row = odbc_fetch_array($results))
and make it
for ($i=0; $row = odbc_fetch_array($results), $i++)
and all calls to the array objects should be like:
$row['location'

Let me know how you get on.

JR
(In need of a cool signature)
 
and all calls to the array objects should be like:
$row['location']

I missed of the ] above

JR
(In need of a cool signature)
 
correct version (sorry)
Code:
for ($i=0; $row = odbc_fetch_array($results); $i++)
and all calls to the array objects should be like:
$row['location']

JR
(In need of a cool signature)
 
first the sql result looks exactly like I expected.
In case you want to see it, here it is:

Code:
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 = 20101

Second, I don't know that I mentioned this but the site_Code is text. We wanted to make it a number but some of are so long that they were causing runtime errors.

So hopefully, the .Get method we used would work for text input param.

Third, I am confused about this line:

$location = odbc_result($results, 0, 'location'))
Where did result come from?

and why is it better than this line:

$results = odbc_exec($conn,$sql);

I just want to know.

When I use this:
$location = odbc_result($results, 0, 'location')),

I get results is undefined.

If I change $results to $conn,
I get this:

Warning: Wrong parameter count for odbc_result() in

 
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."<br><br><br>";

$results = odbc_exec($conn,$sql);

$location = odbc_result($results, 0, 'location'))
echo $location;

?>

The odbc_result (no idea if this is valid statement because I do not work with ODBC connection) is just to output one field (location) of row 0.

I the code above can be run as a test.php file.
Let me know what happens?

PS It seems to take your site_Code well,
however please check on the CASE use. I see in the original a lot of mixture between C and c for the same fields and tables



JR
(In need of a cool signature)
 
sorry,
It appears that tek tips server was temporarily down as I wasn't able to connect till now.

Ok, I ran this code as test.php.

It got the sql statement correct as it did earlier but then I got these errors:

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in e:\inetpub\ on line 19

Warning: Wrong parameter count for odbc_result() in e:\inetpub\ on line 21

Don't know what the first error means.
Based on my asp experience, there appears to be a field name with a different data type that the code is pulling as a different datatype.

I don't know what the second error message means.
 
BTW:
I changed this slightly from this:

$location = odbc_result($results, 0, 'location'))

to this:

$location = odbc_result($results, 0, 'location');
 
Ok JR,
I have made further progress.

I have changed the sql statement slightly so that it will the site_Code as a string like this:

Code:
fctrafic.site_Code = '".$_GET["site_Code"]."'"

as a result, the sql statement returns as:

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 = '20101'

and then this:

$results = odbc_exec($conn,$sql);

$location = odbc_result($results, 'location');
echo $location;

returns this:
Quailbrook Chase

No more errors.

Major progress and thanks to you for this.

Next step now is to integrate them all to return values for form variables..
 
Below the complete code. I could have made some spelling mistakes though. Notice the for statement and the <?=$row["bla"]?> statements

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"]."'";

$results = odbc_exec($conn,$sql);

for($count=0; $row = odbc_fetch_array($results); $count++)
{
  ?>
  <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"><?=$row["site_code"]?></font></td>
         <td class="header"><font size="-3"> TYPE</font></td>
         <td class="name"><font size="-3"><?=$row["types"]?></font></td>
       </tr>
       <tr>
         <td class="header"><font size="-3">AADT</font></td>
         <td class="name"><font size="-3"><?=$row["aadt"]?></font></td>
         <td class="header"><font size="-3">DATE</font></td>
         <td class="name"><font size="-3"><?=$row["fdate"]?></font></td>
       </tr>
       <tr>
         <td class="header"><font size="3">LOCATION</font></td>
         <td class="name"><font size="-3"><?=$row["location"]?></font></td>
         <td class="header"><font size="-3">DISTANCE</font></td>
         <td class="name"><font size="-3"><?=$row["distance"]?></font></td>
       </tr>
       <tr>
         <td class="header"><font size="-3">REF LOCATION</font></td>
         <td class="name"><font size="-3"><?=$row["location2"]?></font></td>
         <td class="header"><font size="-3">DIRECTION</font></td>
         <td class="name"><font size="-3"><?=$row["direction"]?></font></td>
       </tr>
       <tr>
         <td class="header"><font size="-3">FILE NAME</font></td>
         <td class="name"><font size="-3"><?=$row["filename"]?></font></td>
       </tr>
     </table>

     <br>
     <button name="close" value="Close" onClick="window.close()">Close</button>
  </div>
  <?
}

?>

JR
(In need of a cool signature)
 
Oh my goodness!
I owe you my life.
It is working Perfectly!

I have been trying to get this to work forever.
For you to say you are new in this language and you were able to solve a problem that experts could not solve is truly amazing.
This is not a knock on the experts but a true endorsement of your talent.
Thank you very much, very much JR.

I want them to give you 3 stars.

Now can I ask you one more question?

Is it possible to make the filename a link?

I mean to make this:
<td class="name"><font size="-3"><?=$row["filename"]?></font></td>

a link like this:

print "<a href=\"Findfile.php?siteCode="."site_Code"]."\">";
print row["FileName"]."</a>";

so that it becomes a link and when they click it, it opens up a file.

You are great; you have really saved me.
 
Thanks for the compliments,
there are actually greater experts around who I have to thank a lot for their solutions.

One of them actually wrote some info about downloading files which is in a very recent thread, but try this:

Code:
<?

      print "<a href='Findfile.php?siteCode=".$row["site_code"]."'>".$row["FileName"]."</a>";

?>

or this should give the same
Code:
<?

      print "<a href='Findfile.php?siteCode=".$_GET["site_Code"]."'>".$row["FileName"]."</a>";

?>

When you use $_GET in the Findfile.php make sure to echo it just for testing so you can see if the sideCode actually appears.

Also look at the URL which should read [smile]

JR
As a wise man once said: To build the house you need the stone.
Back to the Basics!
 
Code:
<td class="name"><font size="-3"><a href='Findfile.php?siteCode=<?=$row["site_code"]?>'><?=$row["FileName"]?></a></font></td>

Is more what you where after...

JR
As a wise man once said: To build the house you need the stone.
Back to the Basics!
 
This has been a great lesson/help.

It worked real good.
All I had to change was make FileName lower caps.

Thanks again for all of this wonderful help.
My friday has suddenly shaped up to be a happy one.

If you ever get into asp, if you aren't already, please feel free to contact me.

I was going to leave my email but since we have not heard the forum moderators regarding your question about leaving emails, anything you send through here will definitely reach me.

Thanks (again) JR.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top