Member login and recalling database info

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Canabalooza
Forum Newbie
Posts: 5
Joined: Sat Aug 09, 2003 11:08 am

Member login and recalling database info

Post by Canabalooza »

I have a script on my fan site that I have users submit their clans for the game into a text file that then can be read by a php file that displays the information. So far they can add but cannot edit or delete any of the information they put in. On a website I saw a form like mine that you could log into after you logged in automatically re filled in your information into the form. The same form as when you first add you info to the database but it has the previously recorded info. Could someone tell me how I could go about doing this?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

with text files it gets huge fast. with a db it's easier. connect ato the db, recall the info and then match the db feild with the feild on the form and do something like the error checking i talk about in the checkbox thread i have here
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

m3rajk wrote:with text files it gets huge fast. with a db it's easier. connect ato the db, recall the info and then match the db feild with the feild on the form and do something like the error checking i talk about in the checkbox thread i have here
Not everyone have access to db's on their hosts...

Canabalooza:
"...that then can be read by a php file that displays the information"
How? Print the file directly, or fopen() it, reading it's content and then displaying it?

If the later, you can do the same thing, with the form. For each part of the info you can:

Code: Select all

<?php
echo '<input type="text" name="username" value="'.$username.'">';
?>
...or something similiar. Helped?
Canabalooza
Forum Newbie
Posts: 5
Joined: Sat Aug 09, 2003 11:08 am

Post by Canabalooza »

Ok here are the contents of the three files I use,

add.php
<?php
$filename = 'odb.txt'; // edit this

function addlink($homepage,$name,$tag,$email,$leader,$empire,$server,$recruiting) {
global $filename;
$html = "<TABLE cellSpacing=0 cellPadding=2 width='100%' border=0><TBODY><TR class=content><TD width='5%'>$empire</TD><TD width='20%'><A href='$homepage'>$name</A></TD><TD width='20%'>$tag</TD><TD width='20%'><A href='mailto:$email'>$leader</A></TD><TD width='15%'>$server</TD><TD width='20%'>$recruiting</TD></TR></tbody></table> \n";
$fp = fopen($filename, 'a+');
fputs($fp, $html) or die("Could not open file!");
print "<center>Your Outfit was added successfully.</center>";
}

function showlinks() {
global $filename;
$html = implode(file($filename));
echo $html;
}

If (!$name){
print "<center>You must enter an Outfit Name</center><br>";
} elseif (!$tag){
print "<center>You must enter an Outfit Tag</center><br>";
} elseif (!$leader){
print "<center>You must enter an Outfit Leader Name</center><br>";
} elseif (!$email){
print "<center>You must enter an Email Address</center><br>";
} else {
addlink($homepage,$name,$tag,$email,$leader,$empire,$server,$recruiting);

print "<center><A href='index.php'>Back to Outfit Index</A></center>";

}
?>

index.php
<?php

$filename = "odb.txt"; // Edit This

function showlinks() {
global $filename;
$html = implode(file($filename));
print $html;
}

?>

and odb_add.php
<form method="POST" action="add.php">
Outfit Name: <br><input type="text" name="name" size="25"><br><br>
Outfit Leader: <br><input type="text" name="leader" size="25"><br><br>
Outfit Tag: <br><input type="text" name="tag" size="15"><br><br>
Empire: <br><SELECT name="empire">
<OPTION value="<img src=ud.bmp>">Undecided</OPTION>
<OPTION value="<img src=tr.bmp>">Terran Republic</OPTION>
<OPTION value="<img src=nc.bmp>">New Conglomerate</OPTION>
<OPTION value="<img src=vs.bmp>">Vanu Sovereignty</OPTION>
</SELECT><br><br>
Server: <br><SELECT name="server">
<OPTION value=Johari selected>Johari</OPTION>
<OPTION value="Markov">Markov</OPTION>
<OPTION value="Emerald">Emerald</OPTION>
<OPTION value="Konried">Konried</OPTION>
<OPTION value="Werner">Werner</OPTION>
<OPTION value="Undecided">Undecided</OPTION>
</SELECT><br><br>
Outfit Homepage: <br><input type="text" name="homepage" value="Http://www.Planetside.com" size="35"><br><br>
Outfit E-mail: <br><input type="text" name="email" size="35"><br><br>
Recruiting: <br><SELECT name="recruiting">
<OPTION value=Yes selected>Yes</OPTION>
<OPTION value=No>No</OPTION>
</SELECT><br><br>
<p><input type="submit" value="Submit" name="Add"></p>
</form>

So far I don’t have the ability for users to log in just to add to the text file. I want them to log in I could find a set of code easy for that just get one that stores users in a mysql database which I have access to. but then how would I go about setting it up so that when a user logs in and goes back to odb_add.php it fill out the form with what they put in automatically.
Post Reply