Dear:
I have made a web site to manage disc. I use php, sql to query MS Access database. With PHP 4.1.1, everything goes smooth. But with PHP 4.3.7, I have some notices and warning, such as:
Notice: Undefined variable: id in C:\Inetpub\wwwroot\quanlydia\delete.php on line 112
Notice: Undefined variable: title in C:\Inetpub\wwwroot\quanlydia\delete.php on line 112
Notice: Undefined variable: genre in C:\Inetpub\wwwroot\quanlydia\delete.php on line 112
Notice: Undefined variable: quantity in C:\netpub\wwwroot\quanlydia\delete.php on line 112
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in C:\Inetpub\wwwroot\quanlydia\delete.php on line 92
So, I use global variables. Notices disappear but warning still appear. I don't know how to solve this. Everyone have ideas ???
Please help me as soon as possible !!!
Dannis Yang😕 :bemused:
p/s:
this is my code:
//delete_form.php
<?php
global $id,$title,$genre,$quantity;
function HTML_Head() {
echo "
<HTML><HEAD>
<TITLE>Deleting Entry Page</TITLE>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function mainpage_onclick() {
window.location = \"quanlydia.htm\";
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR=\"#ffffff\">
<p align=center> <font face=\"VNI-Netbut\" color = #336699><H1> The Previous Entries in Database</H1></font> </p>
";
}
/==========================================================================================/
function HTML_Form() {
echo "
<br><br><br>
<FORM NAME = \"AccessInterface\" METHOD=post ACTION=\"delete.php\">
<font face=\"Bradley Hand ITC\" color=#2f2fc2 size=6>Please enter the disc's details which you want to delete</font>
<br>
<FONT face=Papyrus color=#ff9933>ID<input id=id name=id TYPE=\"text\" SIZE=\"30\" style=\"Z-INDEX: 100; LEFT: 150px; WIDTH: 427px; POSITION: absolute; HEIGHT: 22px; Design_Time_Lock: true\">
</font>
<br>
<FONT face=Papyrus color=#ff9933>TITLE<input id=title name=title TYPE=\"text\" SIZE=\"30\" style=\"Z-INDEX: 100; LEFT: 150px; WIDTH: 427px; POSITION: absolute; HEIGHT: 22px; Design_Time_Lock: true\">
</font>
<br>
<FONT face=Papyrus color=#ff9933>GENRE<input id=genre name=genre TYPE=\"text\" SIZE=\"30\" style=\"Z-INDEX: 100; LEFT: 150px; WIDTH: 427px; POSITION: absolute; HEIGHT: 22px; Design_Time_Lock: true\">
</font>
<br>
<FONT face=Papyrus color=#ff9933>QUANTITY<input id=quantity name=quantity TYPE=\"text\" SIZE=\"30\" style=\"Z-INDEX: 100; LEFT: 150px; WIDTH: 427px; POSITION: absolute; HEIGHT: 22px; Design_Time_Lock: true\">
</font>
<br>
<INPUT type=\"Submit\" value=\"Delete\">
<input type=\"button\" value=\"Main Page\" LANGUAGE=javascript onclick=\"return mainpage_onclick()\">
</form>
";
}
/==========================================================================================/
function HTML_Foot() {
echo "</body></html>";
}
/==========================================================================================/
function Output_Entries()
{
$cnx = odbc_connect( "danhmucdia" , "", "" );
if (!$cnx)
{
Error_handler( "Error in odbc_connect" , $cnx );
}
$newSQL = "select * from danhmucdia";
$cur= odbc_exec( $cnx, $newSQL);
if (!$cur)
{
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}
echo "<table align= \"center\"border=1 bgcolor=#66ccff cellpading = \"1\" bordercolor = #006699 cellspacing=1 > <tr> <th> ID </th> <th> TITLE </th>".
"<th> GENRE </th> <th> QUANTITY </th> </tr>\n";
$nbrow=0; //Local variable to count number of rows
while( odbc_fetch_row( $cur ) ) {
$nbrow++;
$ID= odbc_result( $cur, 1 );
$Title= odbc_result( $cur, 2 );
$Genre= odbc_result( $cur, 3 );
$Quantity= odbc_result( $cur, 4 );
echo "<tr><td>$ID</td><td>$Title</td>".
"<td>$Genre</td><td>$Quantity</td></tr>\n";
}
echo "<tr><td colspan=2>$nbrow entries </td></tr></table>";
odbc_close( $cnx);
}
HTML_Head();
Output_Entries();
HTML_Form();
HTML_Foot();
?>
// delete.php
<?
global $id,$title,$genre,$quantity;
function HTML_Head() {
echo "
<HTML><HEAD>
<TITLE>Deleting Entry Page</TITLE>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function mainpage_onclick() {
window.location = \"quanlydia.htm\";
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR=\"#ffffff\">
<p align=center> <font face=\"VNI-Netbut\" color = #336699><H1> The Previous Entries in Database</H1></font> </p>
<table align=\"center\" border = 1 bordercolor=#006699 cellpading = 1 cellspacing = 1 bgcolor=#66caff fontcolor=#ffffff>
<tr> <th> ID </th> <th> TITLE </th> <th> GENRE </th> <th>QUANTITY</th> </tr>
";
}
/===============================================================================/
function HTML_Foot() {
echo "
</table>
<a href=\"delete_form.php\"> <font face=\"Curlz MT\" color=#b22222 size=6>Previous Page </font></a>
<br>
<a href=\"quanlydia.htm\"> <font face=\"Curlz MT\" color=#b22222 size=6> Main Page </font></a>
</body></html>";
}
/================================================================================/
function Output_Entries() {
$c = odbc_connect( 'danhmucdia' , '', '' );
// send a simple odbc query . returns an odbc cursor
$newSQL = "select * from danhmucdia";
$cur= odbc_exec( $c, $newSQL );
if (!$cur) {
Error_Handler( "Error in odbc_exec( no cursor returned ) " , $c );
}
# fetch the succesive result rows
while( odbc_fetch_row( $cur ) ) {
$id= odbc_result( $cur, 1 );
$title= odbc_result( $cur, 2 );
$genre= odbc_result( $cur, 3 );
$quantity= odbc_result( $cur, 4 );
print("<tr> <td>$id</td> <td>$title</td> <td>$genre</td> <td>$quantity</td> </tr> \n");
}
#close the connection. important if persistent connection are "On"
odbc_close( $c);
}
/=======================================================================================/
function Error_Handler( $msg, $cnx ) {
echo "$msg \n";
odbc_close( $cnx);
exit();
}
/=======================================================================================/
function Delete_An_Entry($id,$title,$genre,$quantity) {
$c = odbc_connect( 'danhmucdia' , '', '' );
if (!$c) {
Error_handler( "Error in odbc_connect" , $c );
}
$SQL_Exec_String = "delete from danhmucdia where ID='$id'";
$cur= odbc_exec( $c, $SQL_Exec_String );
if (!$cur) {
Error_Handler( "Error in odbc_exec( no cursor returned ) " , $c );
}
odbc_close( $c);
}
/=======================================================================================/
function Database_Entries($msg) {
echo $msg;
}
/========================================================================================/
$strNewEntries = "Updated version of databse (after entries)";
HTML_Head();
Delete_An_Entry($id,$title,$genre,$quantity);
Database_Entries($strNewEntries);
Output_Entries();
HTML_Foot();
?>