Error in accessing database from MS Access using php

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ersahil
Forum Newbie
Posts: 1
Joined: Tue Nov 01, 2011 2:47 am

Error in accessing database from MS Access using php

Post by ersahil »

I am trying to access the MS Access database in a php page. here is the code. I am getting an error Parse error: syntax error, unexpected T_STRING in C:\wamp\www\viewresult.php on line 23. Please help me Guys

Code: Select all

<?php
$conn=odbc_connect('result','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT * FROM result";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
echo "<table><tr>";
echo "<th>admission number</th>";
echo "<th>student name</th></tr>";
echo "<th>marks</th></tr>";
echo "<th>result</th></tr>";
while (odbc_fetch_row($rs))
{
$admission number=odbc_result($rs,"admission number");
$student name=odbc_result($rs,"student name");
$marks=odbc_result($rs,"marks");
$result=odbc_result($rs,"result");
echo "<tr><td>$admission number</td>";
echo "<td>$student name</td></tr>";
echo "<td>$marks</td></tr>";
echo "<td>$result</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
23rd line is $admission number=odbc_result($rs,"admission number");
Last edited by califdon on Tue Nov 01, 2011 11:50 pm, edited 1 time in total.
Reason: Moderator added syntax=php tags to make code readable. Note to poster, please always do this.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Error in accessing database from MS Access using php

Post by manohoo »

Compare this to yours, what's different?

Code: Select all

<?php

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

$sql="SELECT * FROM result";
$rs=odbc_exec($conn,$sql);

if (!$rs) {
	exit("Error in SQL");
}

echo "<table><tr>";
echo "<th>admission number</th>";
echo "<th>student name</th></tr>";
echo "<th>marks</th></tr>";
echo "<th>result</th></tr>";

while (odbc_fetch_row($rs)) {
	$admission_number = odbc_result($rs,"admission number");
	$student_name = odbc_result($rs,"student name");
	$marks = odbc_result($rs,"marks");
	$result = odbc_result($rs,"result");
	echo "<tr><td>$admission_number</td>";
	echo "<td>$student_name</td></tr>";
	echo "<td>$marks</td></tr>";
	echo "<td>$result</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>
Post Reply