html>
<head><title>Current Profile Users</title></head>
<body>
<?
include("config.php"); //calls sql_connect(), sql_accessdb() & sql_submit1()
if (isset($adduser)) {
PrintForm();
exit();
}
else {
sql_connect(); #config.php function
sql_accessdb(); #config.php function
if($submit == "SUBMIT") {
sql_submit1("profile","username","$name", "Your name was added to the database successfully.");
$submit = NULL;
print "<a href=\"$PHP_SELF\"> <- Return to Main</a>";
exit();
}
$names = @mysql_query("SELECT username FROM profile ORDER BY username");
if(! $names) {
print "Error performing query: " . mysql_error();
exit();
}
while ($row = mysql_fetch_array($names)) {
print $row["username"] . "<BR>";
}
//add a name
print "<a href=\"$PHP_SELF?adduser=1\">Add a name</a>";
}
function PrintForm() {
?>
<form action="names.php" method="post">
<table align=center>
<tr>
<td><div align="right">Character Name:</div></td>
<td><input type="text" name="name"></td>
<td colspan="2"><div align="center">
<input type="submit" name="submit" value="SUBMIT">
</div></td>
</tr>
</table>
</form>
<?
}
function sql_submit1($table, $field, $data, $success) {
$sql = "INSERT INTO $table SET
$field='$data'";
if( @mysql_query($sql)) {
print $success;
}
else {
print "Error submitting to database";
}
}
?>
Theres the code for the page, the form function is near the bottom.