PDA

View Full Version : Problem with if()


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. :)

Kiwi
12-25-2002, 01:21 AM
Are you sure that the value of $step is available after you click the button? In the newer versions of PHP, the globals are off, which means that you will have to extract the value of $step from the array (if I remember rightly, that's done by import_request_variables("g")). Alternatively, you may be able to read it directly from the array with $_GET("step").

In either case, echo $step and see if it's being set properly.

Threenet
12-25-2002, 01:33 AM
It's showing up in the title bar:

"&step=go"

But is not being set.

Threenet
12-25-2002, 01:34 AM
That was the problem. My refrence book didn't say anything about it.

Thanks for the help!

Kiwi
12-25-2002, 02:08 AM
It's a fairly recent change to the default settings, so a lot of books haven't caught up with it yet. Luckily, a lot of servers haven't either.