Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 04:37
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  PHP, Perl, ASP, JSP, CFM (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Jorge Solis, nothingGrinder)
| | |-+  $newentry ="$msg_old ,$username ";
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: $newentry ="$msg_old ,$username ";  (Read 1378 times)
till
Seasoned Programmer
***
Posts: 200



View Profile WWW Email
« on: 08/20/02, 06:51 »

hi. tilll again.
another question:


<?
include ('register.inc');
$user = "$username ";
$lock = "passwort = $pw";

$register_file = "register.inc";

if ($username == $name) {
   $result="Name already in Use";
   print "&result=".$result;}

else{
             
        $msg_old = $name ;
             $newentry ="$msg_old ,$username ";


    $fp = fopen("$user.txt","w+");
    fwrite($fp, $lock, 800);
    fclose( $fp );

 $fp = fopen($register_file, "a+");
    fwrite($fp, $newentry, 800);
    fclose( $fp );


$result="Hallo " .$username."      Du wurdest registriert";

print "&result=".$result;
        }
?>

register.inc   :
<?
$name = "till";
?>


what i would like to do is: add a new name into register.inc,       my code doesnt do it.
it looks like:

<?
$name = "till";
?>,newname1,newname2........


but iwant it tobe like this:

<?
$name = "till";
$name = "newname1";
?>


anybody please help.
till.
« Last Edit: 08/20/02, 07:00 by till » Logged
Flash-db
Administrator
Systems Administrator
*****
Posts: 1867



View Profile WWW
« Reply #1 on: 08/21/02, 04:40 »

Ok - I think it would be better to read and write to a plain text file then trying to write a new php file for register.inc.  The code looks a bit funky as well.

Quote

<?
$name = "till";
?>,newname1,newname2........


So just write a simple comma delimited file - basically what you where doing - so each of your usernames are seperated in by a comma in your text file - without trying to write new php code.

so you text file would just look like

newname1,newname2,newname3, etc etc


Then to Check if a user name already exists in that file you could use something like this:

Code:

$fp = fopen ("register.txt","r");

$row = 0;

while ($data = fgetcsv ($fp, 10000, ",")) {

   if ($data[$row] == "$name") {

                        print "&result="Name already in use";
                        break;

   }

   $row++;

}


Well the rest of it would be the same - It's late here and I'm not sure if i got that entirely correct - but hopefully you can see the idea.  

fgetcsv function can be found here:
http://www.php.net/manual/en/function.fgetcsv.php

Basically just an easy way of reading in comma seperated values (csv) from text files.

If it finds a match to the username entered by the user - then it will break and print out the result indicating it's already in use.  You will have to work in some logic their, and I'm really not sure if this is the best way...
Logged

-Jeff.
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything