Gossamer Forum
Home : General : Perl Programming :

Modifying a registry in a database

Quote Reply
Modifying a registry in a database
  I have a database with IDs, username, password, site description, etc...
What I want is to according to a user entry modify his information. I tried the following code:
Code:
open (DB, "<$arq_membros") or &cgierr("Erro em modificar em cadastrar.cgi. Impossível abrir arquivos db: $arq_membros. Motivo: $!");
$found = 0;
LINE: while (<DB> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = split(/\|/,$_);
if ($data[1] eq "$in{'usuario'}") {
if ($data[6] eq "$in{'senha'}") {
$temp_data = join ("\|",$data[0],$data[1],$in{'url'},$in{'banner'},$in{'nome'},$in{'email'},$data[6],$data[7],$in{'descricao'},$data[9],$data[10],$data[11]);
$temp_data .= "\n"; $found = '1'; $new_data .= $temp_data;}
else { &site_html_add_failure ("Senha incorreta"); exit; }
}
else { $new_data .= @data; }
if ($found) { last LINE; }
}
close DB;

But with this, when the routine find the username, it modifies it but all the information that comes after this line is lost.
What to do know???
Quote Reply
Re: Modifying a registry in a database In reply to
  Please.. Someone...
Quote Reply
Re: Modifying a registry in a database In reply to
I am not sure of that specific problem, but I do see this:

Quote:
else { $new_data .= @data; }

Since you want a joined list, not one that is separated into individual fields (which is what @data is), I think that should be:

Quote:
else { $new_data .= $_; }

That passes the database record back to $new_data as it is in the database.

That might be what is causing the problem. I hope this helps.
Quote Reply
Re: Modifying a registry in a database In reply to
  Thank you. This helped, but this is not the problem.
The problem is:
if the username is found it goes to the end of the file without puting the rest of the information on the array that will be printed to the database.
I think I understand now how to solve this problem..
Quote Reply
Re: Modifying a registry in a database In reply to
Ah, then the line, "if ($found) { last LINE; }" is the problem because that tells the script to skip the rest of the database. What you need to do is change the action to read in the rest of the database and append each line to $new_data.

I hope this helps.