WildWayz
17-01-2001, 10:21
Hi ya
I have been writing some PHP stuff last night considering my friggin ISDN is out of action until BT fix the cabling.
So far, I have written a script to authorise users that are in a MySQL database - that works fine. The problem I have at the moment, is that I am making an add new users script that has checking to see if a username is already in the database, and if there is, it gets u to re-enter the info again.
Now, the problem is that it does this ok, but it isn't writing the data to the mysql database if the username is unique.
It worked before I done this checking tho.
The code is
<?
require("config.php");
if ((!$first_name) || (!$last_name) || (!$username) || (!$password)) {
header("Location: view_adduser.php");
exit;
}
$table_name = "users";
$connection = @mysql_connect("$servername", "$dbusername", "$dbpassword")
or die("Couldn't connect.");
$db = mysql_select_db($dbname, $connection)
or die("Couldn't select database.");
$chk_id = "SELECT username FROM $table_name WHERE username = \"$username\"";
$chk_id_res = @mysql_query($chk_id,$connection) or
die("Couldn't execute query.");
$chk_id_num = mysql_num_rows($chk_id_res);
if ($chk_id_num != "0") {
header("Location: view_adduser.php");
exit;
} else
{
$sql = "INSERT INTO $table_name (id, first_name, last_name, username, password, email_address, enroll_date, status) VALUES (\"\", \"$first_name\", \"$last_name\", \"$username\", password(\"$password\"), \"$email_address\", \"$enroll_date\", \"$status\")";
$result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
}
?>
<HTML>
<HEAD>
<TITLE>Add a New User</TITLE>
</HEAD>
<BODY>
<H1>Added the user:</H1>
<P><STRONG>First Name:</STRONG><BR>
<? echo "$first_name"; ?></p>
<P><STRONG>Last Name:</STRONG><BR>
<? echo "$last_name"; ?></p>
<P><STRONG>Username:</STRONG><BR>
<? echo "$username"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$password"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$email_address"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$enroll_date"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$status"; ?></p>
<P><a href="view_adduser.php">Add Another</a></p>
</BODY>
</HTML>
Any help would be appreciated! :)
--WildWayz
I have been writing some PHP stuff last night considering my friggin ISDN is out of action until BT fix the cabling.
So far, I have written a script to authorise users that are in a MySQL database - that works fine. The problem I have at the moment, is that I am making an add new users script that has checking to see if a username is already in the database, and if there is, it gets u to re-enter the info again.
Now, the problem is that it does this ok, but it isn't writing the data to the mysql database if the username is unique.
It worked before I done this checking tho.
The code is
<?
require("config.php");
if ((!$first_name) || (!$last_name) || (!$username) || (!$password)) {
header("Location: view_adduser.php");
exit;
}
$table_name = "users";
$connection = @mysql_connect("$servername", "$dbusername", "$dbpassword")
or die("Couldn't connect.");
$db = mysql_select_db($dbname, $connection)
or die("Couldn't select database.");
$chk_id = "SELECT username FROM $table_name WHERE username = \"$username\"";
$chk_id_res = @mysql_query($chk_id,$connection) or
die("Couldn't execute query.");
$chk_id_num = mysql_num_rows($chk_id_res);
if ($chk_id_num != "0") {
header("Location: view_adduser.php");
exit;
} else
{
$sql = "INSERT INTO $table_name (id, first_name, last_name, username, password, email_address, enroll_date, status) VALUES (\"\", \"$first_name\", \"$last_name\", \"$username\", password(\"$password\"), \"$email_address\", \"$enroll_date\", \"$status\")";
$result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
}
?>
<HTML>
<HEAD>
<TITLE>Add a New User</TITLE>
</HEAD>
<BODY>
<H1>Added the user:</H1>
<P><STRONG>First Name:</STRONG><BR>
<? echo "$first_name"; ?></p>
<P><STRONG>Last Name:</STRONG><BR>
<? echo "$last_name"; ?></p>
<P><STRONG>Username:</STRONG><BR>
<? echo "$username"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$password"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$email_address"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$enroll_date"; ?></p>
<P><STRONG>Password:</STRONG><BR>
<? echo "$status"; ?></p>
<P><a href="view_adduser.php">Add Another</a></p>
</BODY>
</HTML>
Any help would be appreciated! :)
--WildWayz