Jump to content

ACCESS & PHP Select Query Issue


Recommended Posts

I have a client who needs a portal web page built so their clients can access limited information from their database.  The unfortunate part is the program they are using (and don't/won't replace), uses ACCESS as it's database.

 

My ODBC connection works great.  My problem comes when I try to retrieve information from a field name that has a space in it, i.e. Patient Number.  I can't change the field names and no matter what I use to enclose it (`,', or "), it doesn't seem to work.  I get the "no tuples..." error message.  Is there anything else I can try to solve this situation?

 

Thanks for your help.

 

<?php


$conn=odbc_connect('patton','','','SQL_CUR_USE_ODBC');
if (!$conn)
  {exit("Connection Failed: " . $conn);}

print('<html>

<head>

<title>PHP and MS ACCESS</title>

</head>');

print('<body>');

print('<table align="center" width=90%>');

print('<tr><th>CardID</th><th>CardName</th><th>Type</th>

<th>Expire</th><th>Number</th><th>Credit</th><th>Phone</th>

<th>Address</th><th>City</th><th>State</th><th>Zip</th></tr>');

if($conn)
{
$sql="select * from Patient where `Patient Number`='1'";
$row=odbc_exec($conn, $sql);

    while(odbc_fetch_row($row))
     {
          $cardid=odbc_result($row,1);
          $name=odbc_result($row,2);
          $type=odbc_result($row,3);
          $expired=odbc_result($row,4);
          $card_num =odbc_result($row,5);
          $credit =odbc_result($row,6);
          $phone =odbc_result($row,7);
          $address =odbc_result($row,;
          $city =odbc_result($row,9);
          $state =odbc_result($row,10);
          $zip =odbc_result($row,11);

print('<tr><td>'.$cardid.'</td><td>'. $name.'</td><td>'.$type.'</td><td>'.$expired.'</td><td>'.$card_num.'</td><td>'.$credit.'</td><td>'. $phone.'</td><td>'.$address.'</td><td>'.$city.'</td><td>'.$state.'</td><td>'.$zip.'</td></tr>');
     }
}

print('</table>');
print('</body>');
print('</html>');
?>

Link to comment
https://forums.phpfreaks.com/topic/162922-access-php-select-query-issue/
Share on other sites

Hello,

 

The backticks (`) should be the proper formatting for this according to PHP's legal-names. However, can you set the code to use the backticks and copy the error to here? I think pasting the exact output error and/or the apache error_log would help those who view the thread more info to help out.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.