Page 1 of 1

Error in accessing database from MS Access using php

Posted: Tue Nov 01, 2011 2:50 am
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");

Re: Error in accessing database from MS Access using php

Posted: Tue Nov 01, 2011 1:09 pm
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>";
?>