Threenet
12-25-2002, 12:37 AM
I can't seem to get this script to work. I need to have data from a form submitted to a database. The problem is, I can't make the form continue. When I hit go, it just reloads the page. Here's my code
form.php:
<?php
require("config.php");
if ( $step == "go" )
{
if(!makeAdmin($username, $password))
{
print "Error: $dberror<br>";
}
else
{
print "Your data has been sucessfully submitted. If you would like to make another admin, click <a href=\"$PHP_SELF\">here</a>. Otherwise, delete this file.<br>";
print "<b>DATA SUBMITTED:</b>";
print "Username: $form_username";
print "Password: $form_password";
}
}
else
{
?>
<html>
<head>
<title><?=$sitename?> - Make an Administrator</title>
</head>
<body bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
<form action="<?=$PHP_SELF?>" method="GET">
<font face="Arial">You need to make an administrative user. Enter the information needed and click submit<br><br>
<b>Username</b><input type="text" name="form_username"><br>
<b>Password</b><input type="password" name="form_password">
<input type="submit" name="step" value="go">
</form>
<?php
}
?>
And here's a copy of the function needed to run this script, (in config.php):
function makeAdmin($username, $password)
{
global $sql_host;
global $sql_data;
global $sql_user;
global $sql_pass;
global $tbl_users;
global $password;
global $username;
$link = mysql_connect($sql_host, $sql_user, $sql_pass);
if(!$link)
{
$dberror = mysql_error();
return false;
}
if(!mysql_select_db($sql_data, $link))
{
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO `$tbl_users` ( `id` , `username` , `password` , `accesslevel` ) VALUES ('', '$username', '$password', '0')";
if(!mysql_query($query, $link))
{
$dberror = mysql_error();
return false;
}
return true;
}
I have no clue what the problem is. My webserver may be playing tricks on me again though. It's done it before. :)
form.php:
<?php
require("config.php");
if ( $step == "go" )
{
if(!makeAdmin($username, $password))
{
print "Error: $dberror<br>";
}
else
{
print "Your data has been sucessfully submitted. If you would like to make another admin, click <a href=\"$PHP_SELF\">here</a>. Otherwise, delete this file.<br>";
print "<b>DATA SUBMITTED:</b>";
print "Username: $form_username";
print "Password: $form_password";
}
}
else
{
?>
<html>
<head>
<title><?=$sitename?> - Make an Administrator</title>
</head>
<body bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
<form action="<?=$PHP_SELF?>" method="GET">
<font face="Arial">You need to make an administrative user. Enter the information needed and click submit<br><br>
<b>Username</b><input type="text" name="form_username"><br>
<b>Password</b><input type="password" name="form_password">
<input type="submit" name="step" value="go">
</form>
<?php
}
?>
And here's a copy of the function needed to run this script, (in config.php):
function makeAdmin($username, $password)
{
global $sql_host;
global $sql_data;
global $sql_user;
global $sql_pass;
global $tbl_users;
global $password;
global $username;
$link = mysql_connect($sql_host, $sql_user, $sql_pass);
if(!$link)
{
$dberror = mysql_error();
return false;
}
if(!mysql_select_db($sql_data, $link))
{
$dberror = mysql_error();
return false;
}
$query = "INSERT INTO `$tbl_users` ( `id` , `username` , `password` , `accesslevel` ) VALUES ('', '$username', '$password', '0')";
if(!mysql_query($query, $link))
{
$dberror = mysql_error();
return false;
}
return true;
}
I have no clue what the problem is. My webserver may be playing tricks on me again though. It's done it before. :)