1,075,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Posts by azlanaziz

Hi i have an example on dropdown + ms access + php

page1:

<font face="Verdana" color="#CC0000">
                    <?php
	$strConn = new COM("ADODB.Connection") or die("Cannot start ADO");
	$strConn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("db/dbExam.mdb")); 
	$strSQL = "SELECT * FROM tblKursus";
	$objRec = $strConn->Execute($strSQL);
      
    
?>        
                                                                                                                                              <form name="form1" method="post" action="process.php">
   
<select name="pilihankursus">
    <?php 
While (!$objRec->EOF)
{
?>   
<option value=<?php print $objRec->Fields(2)->Value;?>><?php print $objRec->Fields(1)->Value;?></option>
 <?php
	$objRec->MoveNext();
}
?> 
</select>
   <input type="submit" name="Submit" value="Submit"/>

</form>

page2 process.php:

<?php
	$strConn = new COM("ADODB.Connection") or die("Cannot start ADO");
	$strConn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("db/dbExam.mdb")); 
$strVar .= "KodKursus = '".$_POST["pilihankursus"]."' ";
      
      $SKursus = $_POST['pilihankursus'];
      
      echo "Variable yang dipost dari page lalu(default.php) ialah";
      echo "<p style=\"color:#FF8000\"> $SKursus</p>";
      echo "pembolehubah ini(variable)";
      echo "<p style=\"color:#0080ff\">$strVar</p>";
      echo "akan menentukan table yang akan dipilih untuk dipapar dan seterusnya untuk disimpan data-data ke dalamnya";
?>

<?php
$db_conn = new COM("ADODB.Connection");  
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("db/dbExam.mdb").";";  
$db_conn->open($connstr);  
$rS = $db_conn->execute("SELECT  * from $SKursus");  



$f1 =  $rS->Fields(0); 
$f2 =  $rS->Fields(1);
$f3 =  $rS->Fields(2);
$f4 =  $rS->Fields(3);
$f5 =  $rS->Fields(4);
$f6 =  $rS->Fields(5);
$f7 =  $rS->Fields(6);
$f8 =  $rS->Fields(7);
$f9 =  $rS->Fields(8);
?>
</br>
        <table>
            <tr>
                <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="post" action="update.php">
<tr> 
<td> 
     
    <input name="txtKursus"   type="text" id="txtKursus" value="<?php print $SKursus;   ?>">
   
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
<td  align="center"><strong>Id</strong></td>
<td align="center"><strong>NoPendaftaran</strong></td>
<td align="center"><strong>S1</strong></td>
<td align="center"><strong>S2</strong></td>
<td align="center"><strong>S3</strong></td>
<td align="center"><strong>S4</strong></td>
<td align="center"><strong>S5</strong></td>
<td align="center"><strong>S6</strong></td>
<td align="center"><strong>S7</strong></td>
</tr>

<?php 
while (!$rS->EOF)  
{  ?>
<tr>
  
    <td  align="center"><input name="id[]" type="hidden"  type="text" id="id" value="<?php print $f1->value;   ?>"><?php $id[] = $f1->value;?> <?php echo $f1->value;?></td>
    <td align="center"><input  name="NoPendaftaran[]" type="text" STYLE="color: #FFFFFF; font-family: Arial;   font-size: 12px; background-color: #72A4D2;" size="10" maxlength="30" id="NoPendaftaran" value="<?php print $f2->value;  ; ?>"></td>
<td align="center"><input name="S1[]" size="4"  type="text" id="S1" value="<?php print $f3->value;   ?>"></td>
    <td align="center"><input  name="S2[]" size="4" type="text" id="S2" value="<?php print $f4->value;   ?>"></td>
    <td align="center"><input  name="S3[]" size="4" type="text" id="S3" value="<?php print $f5->value;   ?>"></td>
    <td align="center"><input  name="S4[]" size="4" type="text" id="S4" value="<?php print $f6->value;   ?>"></td>
    <td align="center"><input   name="S5[]"size="4" type="text" id="S5" value="<?php print $f7->value;   ?>"></td>
    <td align="center"><input  name="S6[]" size="4" type="text" id="S6" value="<?php print $f8->value;   ?>"></td>
    <td align="center"><input  name="S7[]" size="4" type="text" id="S7" value="<?php print $f9->value;   $rS->MoveNext();  ?>"></td>
 
    </tr>
    
<?php
}
?>
  


<tr>
<td colspan="9" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
        <?php
$rS->Close();  
$db_conn->Close();  
?><br>
azlanaziz
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

ok i have solved this:
in the second page put his:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
     
        
        <?php
         $strConn2 = new COM("ADODB.Connection") or die("Tidak dapat buat sambungan ADO");
$strConn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("./dbExam.mdb"));
 
 
 // Create a new record set
$rs = new COM("ADODB.Recordset");
// open the record set, and select the Username / Location URL / Time Logged In
$rs->Open("select * from BC101", $strConn2, "3", "1"); 
$bilPel = $rs->recordcount();
// This is the record count part <<<<<<<<<<<<<<<<<<<<<<<<
echo $rs->recordcount() ." : Bilangan pelajar yang ada di dalam rekod En Abdullah Yusof <p></p>";
//close the ADO connections and release resources
$rs->Close(); 
$strConn2->Close(); 
$rs = null; 
$strConn2 = null;  
    
        $strConn = new COM("ADODB.Connection") or die("Tidak dapat buat sambungan ADO");
$strConn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("./dbExam.mdb"));
        $i = 0;
       
        while ($i < $bilPel){
        $S1 = $_POST['S1'][$i];
        $S2 = $_POST['S2'][$i];
        $S3 = $_POST['S3'][$i];
        $S4 = $_POST['S4'][$i];
        $S5 = $_POST['S5'][$i];
        $S6 = $_POST['S6'][$i];
         $S7 = $_POST['S7'][$i];
     $id = $_POST['id'][$i];
      $str = "$id";
$string = intval($id); 
     echo "$S1 , $S2, $S3: $id .$string. $str <br />";
   
  $strSQL = "update BC101 set S1 = '$S1', S2 = '$S2', S3 = '$S3',S4= '$S5', S5='$S5', S6='$S6', S7='$S7' where id = $str";
  $flgSave = $strConn->Execute($strSQL);

          ++$i;
     echo "$S1 <em>Dengan id: $id Telah Dikemaskini!</em><br /><br />";
    
        }
        	$strConn->Close();
	$strConn = null;
        ?>

    </body>
</html>
azlanaziz
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hi i'm unable to do multiple update (using Ms Acess because of restrictions). I try to do through ADO method (also because of restriction , x ODBC). The operation will break when reaching the script to update on the second page. Can you guys point where did i went wrong?

1st page:

<?php
$db_conn = new COM("ADODB.Connection");  
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./dbExam.mdb").";";  
$db_conn->open($connstr);  
$rS = $db_conn->execute("SELECT  * from BC101");  
$f1 =  $rS->Fields(0); 
$f2 =  $rS->Fields(1);
$f3 =  $rS->Fields(2);
$f4 =  $rS->Fields(3);
$f5 =  $rS->Fields(4);
$f6 =  $rS->Fields(5);
$f7 =  $rS->Fields(6);
$f8 =  $rS->Fields(7);
$f9 =  $rS->Fields(8);
?>
</br>
<?php 
while (!$rS->EOF)  
{  ?>
<tr>
  
    <td  align="center"><input name="id[]" type="hidden"  type="text" id="id" value="<?php print $f1->value;   ?>"><?php $id[] = $f1->value;?> <?php echo $f1->value;?></td>
    <td align="center"><input  name="NoPendaftaran[]" type="text" STYLE="color: #FFFFFF; font-family: Arial;   font-size: 12px; background-color: #72A4D2;" size="15" maxlength="30" id="NoPendaftaran" value="<?php print $f2->value;  ; ?>"></td>
<td align="center"><input name="S1[]"   type="text" id="S1" value="<?php print $f3->value;   ?>"></td>
    <td align="center"><input  name="S2[]"  type="text" id="S2" value="<?php print $f4->value;   ?>"></td>
    <td align="center"><input  name="S3[]"  type="text" id="S3" value="<?php print $f5->value;   ?>"></td>
    <td align="center"><input  name="S4[]"  type="text" id="S4" value="<?php print $f6->value;   ?>"></td>
    <td align="center"><input   name="S5[]" type="text" id="S5" value="<?php print $f7->value;   ?>"></td>
    <td align="center"><input  name="S6[]" type="text" id="S6" value="<?php print $f8->value;   ?>"></td>
    <td align="center"><input  name="S7[]"  type="text" id="S7" value="<?php print $f9->value;   $rS->MoveNext();  ?>"></td>
 
    </tr>
    
<?php
}
?>
  


<tr>
<td colspan="9" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
        <?php
$rS->Close();  
$db_conn->Close();  
?>

2nd page

<?php
         $strConn2 = new COM("ADODB.Connection") or die("Cannot Connect: ADO");
$strConn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("./dbExam.mdb"));
 
 
 // Create a new record set
$rs = new COM("ADODB.Recordset");
 
$rs->Open("select * from BC101", $strConn2, "3", "1"); 
$bilPel = $rs->recordcount();
 
echo $rs->recordcount() ." : Number of records <p></p>";
//close the ADO connections and release resources
$rs->Close(); 
$strConn2->Close(); 
$rs = null; 
$strConn2 = null;  
    
        $strConn = new COM("ADODB.Connection") or die("Cannot connect: ADO");
$strConn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("./dbExam.mdb"));
        $i = 0;
       
        while ($i < $bilPel){
        $S1 = $_POST['S1'][$i];
        $S2 = $_POST['S2'][$i];
        $S3 = $_POST['S3'][$i];
        $S4 = $_POST['S4'][$i];
        $S5 = $_POST['S5'][$i];
        $S6 = $_POST['S6'][$i];
         $S7 = $_POST['S7'][$i];
     $id = $_POST['id'][$i];
     echo "$S1 , $S2, $S3: $id ... <br />";
   
 $strSQL = "update BC101 set S1 = '$S1', S2 = '$S2', S3 = '$S3',S4= '$S5', S5='$S5', S6='$S6', S7='$S7' where id = '$id'";
  $flgSave = $strConn->Execute($strSQL);

          ++$i;
         
        }
        	$strConn->Close();
	$strConn = null;
        ?>
azlanaziz
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
 
© 2013 DaniWeb® LLC
Page rendered in 0.0440 seconds using 2.51MB