how replace a record ?
This example delete a record and
add a record with a new field value.
// createtable.php
<?
$dbname = "players.dbf";
$def = array
(
array("record", "N",8,0),
array("account", "C",10),
array("password", "C",5),
array("name", "C",30)
);
if (!dbase_create($dbname, $def))
{
print "<strong>Error! <BR> Try: chmod 707 tabledirectory</strong>";
}
else
{
print "<strong>The table ".$dbname." was created !</strong>";
}
?>
// addrecord.php
// just a test, you can add more features to send the data by a html form and validate the account
<?
$db=dbase_open("players.dbf",);
$nextrecord = 1;
for ($a=1; $a <= $nr; $a++)
{
$rec = dbase_get_record($db, $a);
$nextrecord = $rec[0]+1;
}
$def = array ($nextrecord,'hsanchez', 'hugol', 'hugo sanchez');
dbase_add_record($db, $def);
dbase_close($db);
?>
// modify.htm
<FORM ACTION='modify.php' METHOD='post'>
<TABLE BORDER='9'>
<TR>
<TD>Account</TD><TD>Password</TD><TD>Name</TD>
</TR>
<TR>
<TD><INPUT TYPE='TEXT' SIZE='10' MAXLENGTH='10' NAME='f_account></TD><TD><INPUT TYPE='PASSWORD' SIZE='5' MAXLENGTH='5' NAME='f_password'></TD><TD><INPUT TYPE='TEXT' SIZE='30' MAXLENGTH='30' NAME='f_name'></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE='Submit' VALUE='Modify'><BR>
</FORM>
</CENTER>
</BODY>
</HTML>
// modify.php
<?
$exist = 0;
$db=dbase_open("players.dbf",0);
$nr = dbase_numrecords($db);
if ($nr==0)
{
print "There's no players !";
}
else
{
for ($a=1; $a <= $nr; $a++)
{
$rec = dbase_get_record($db, $a);
if ( !strcasecmp (trim($rec[1]), trim($f_account)) and !strcasecmp (trim($rec[2]), trim($f_password)))
{
$exist = 1;
$nrm = $a;
break;
}
}
}
dbase_close($db);
if ($exist == 1) {
if ($f_name and $f_account and $f_password)
{
$db=dbase_open("players.dbf",2);
dbase_delete_record($db,$nrm);
dbase_pack($db);
dbase_close($db);
$db=dbase_open("players.dbf",2);
$def = array($nrm,trim($f_account),$f_password,trim($f_name));
dbase_add_record($db, $def);
print "The name was updated !";
}
else
{
print "<strong>Error, enter alll data!</strong>";
}
}
if ($exist == 0)
{
print "<strong>Error, the data is not valid !</strong>";
}
?>
That's all !
I know that there is a dbase-replace-record function but i could use it.