alumbagreenz 0 Newbie Poster

Hi, i am trying to create a function that will allow me to update names in a textfile i got. I am actually having problems creating the function. I wAS FOLLOWING AN EXAMPLE I FOUND IN A C++ BOOK, DOING IMPLEMENTATION, BUT GOT MIXED UP. CAN SOMEONE PLEASE HELP ME. THANK YOU.

HERE IS THE CODE:

<?php
$filename = "names.txt";
$data = array();
$key =1;

# get the data from current file
    if (file_exists($filename))
        $data = parse_ini_file($filename, true);
 function txtupdate($k)
{
$fp = fopen($filename, 'w');

    ksort($data);
    foreach ($data as $key=>$dataArray) {
             fwrite($fp, "[$key]\n");
             foreach ($dataArray as $k => $v) {
                      fwrite($fp, "$k=$v\n");
             }
             fwrite($fp, "\n");
    }
    fclose($fp);
 }
?>
alumbagreenz 0 Newbie Poster

ok. that worked perfectly. thanks a lot.
I got another question. i am now trying to go back to getdata.php if the MAC address already exists. how can i do that?

<?php 

$Ncontrol = @$_POST["ncontrol"]; 
$Fdate = @$_POST["hoy"]; 
$dMAC = @$_POST["mac1"];
$dMAC1 = @$_POST["mac2"];
$dMAC2 = @$_POST["mac3"];
$dMAC3 = @$_POST["mac4"];
$dMAC4 = @$_POST["mac5"];
$dMAC5 = @$_POST["mac6"];
// Set the string to be written to the file 
//save numero de control
$values = "$Ncontrol \t\t\t\t\t\t\t\t\t"; 
//save MAC 
$values .= "$dMAC:$dMAC1:$dMAC2:$dMAC3:$dMAC4:$dMAC5 \t\t\t\t";
//save date
$values .= "$Fdate\r\n"; 


   /*
 
  if ( (!$Ncontrol)||(!$Fdate)||(!$dMAC) ||(!$dMAC1)||(!$dMAC2)||(!$dMAC3)||(!$dMAC4)||(!$dMAC5)){ 
    echo "Revise lo siguiente por favor:<BR>"; 
    if(!$Ncontrol){ 
        echo "Ingrese el Numero de Control Por favor<BR>"; 
    }
    if(!$Fdate){ 
        echo "Fecha esta vacio!<BR>"; 
    } 
    if(!$dMAC){ 
        echo "MAC 1 vacio<BR><BR>"; 
    } 
    if(!$dMAC1){ 
        echo "MAC 2 vacio<BR><BR>"; 
    } 
    if(!$dMAC2){ 
        echo "MAC 3 vacio<BR><BR>"; 
    } 
    if(!$dMAC3){ 
        echo "MAC 5 vacio<BR><BR>"; 
    } 
    if(!$dMAC4){ 
        echo "MAC 6 vacio<BR><BR>"; 
    } 
    if(!$dMAC5){ 
        echo "MAC 7 vacio<BR><BR>"; 
    } 
  }else{ */
  // Open the file for reading and writing 
  $fp = @fopen("MACS.data", "a+") or die("No puede abrir MAC.data para escribir!");
  $filecontents = fread($fp,filesize("MACS.data")); 
  if(strpos($filecontents,"$dMAC:$dMAC1:$dMAC2:$dMAC3:$dMAC4:$dMAC5")===FALSE){
      $numBytes = @fwrite($fp, $values) or die("No puede escribir al archivo!");
  }else{
       echo("<SCRIPT LANGUAGE='JavaScript'>
  window.alert('THIS MAC ADDRESS IS ALREADY REGISTERED!!')
  </SCRIPT>"); 
  }
/*}  */
@fclose($fp);
?>
alumbagreenz 0 Newbie Poster

hi, i am not using a database because with the MAC address, i will be working with a proxy server(squid) to validate the MAC addresses so that every person can nagvigate automatically once registered. That's the reason why i am using the text file.

Ok. i can use one of the fuctions u told me about but how can i link the text in the textbox to the functions? How can i assign the text given as a variable for use of the function??

alumbagreenz 0 Newbie Poster

Hi good day. i am designing a little project for school. This project is to register the MAC address of the laptops of every student in the school.
My problem is, when i put in the student's MAC address in the textbox, i would like the little search algorithm i got to revise the text file to see if the MAC address is already registered.
I am facing problems with the textbox content to do the search.

Contains two files : getdata.php

<?php
$hoy=date("d-m-y");
?>

<html> 
  <head> 
    <meta http-equiv="content-type" content="text/html; charset=windows-1250">
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <title> Register MAC </title> 
  </head> 
  <body bgcolor="#ffffff"> 
  
    <form action="savedata.php" method="post"> 
    <table class="fd">
      <tr><td>Identification No.: <input type="text" name="ncontrol" MAXLENGTH ="8" size="30"><br></td></tr>
      <tr><td>MAC Address:<input type="text" name="mac1" size = "1" MAXLENGTH="2" class="macs">:
                          <input type="text" name="mac2" size = "1" MAXLENGTH="2" class="macs">:
                          <input type="text" name="mac3" size = "1" MAXLENGTH="2" class="macs">:
                          <input type="text" name="mac4" size = "1" MAXLENGTH="2" class="macs">:
                          <input type="text" name="mac5" size = "1" MAXLENGTH="2" class="macs">:
                          <input type="text" name="mac6" size = "1" MAXLENGTH="2" class="macs"></td>
      </tr>
      <tr><td>Date Registered: <?php echo "<input type='text' name='hoy' id='hoy' value='$hoy'>"; ?></td></tr>
    </table>
      <input type="submit" value="Save>>"> 
    </form> 
  </body> 
</html> 


<?php

?>

and savedata.php

<?php 
$Ncontrol = @$_POST["ncontrol"]; 
$Fdate = @$_POST["hoy"]; 
$dMAC = @$_POST["mac1"];
$dMAC1 = @$_POST["mac2"];
$dMAC2 = @$_POST["mac3"];
$dMAC3 = @$_POST["mac4"];
$dMAC4 = @$_POST["mac5"];
$dMAC5 = @$_POST["mac6"];
// Set the string to be written to the file 
//save numero de control
$values = "$Ncontrol \t\t\t\t\t\t\t\t\t"; 
//save MAC 
$values .= "$dMAC:$dMAC1:$dMAC2:$dMAC3:$dMAC4:$dMAC5 \t\t\t\t";
//save date
$values .= "$Fdate\r\n"; 

// Open the file for reading …