WildWayz
Wed 17th Jan '01, 7:47am
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 (Done in PHP3.0.7)
<?
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>
Can you help, or tell me a better/easier way to do this?
Also, how can I change the date from YYYY-MM-YY into a different format ?
Any help would be appreciated! :)
--James
PS - what my aim to do is to write a script that does this....
Write a site that is in PHP with a MySQL backend.
Enable news posting.
Enable review posting with rating system and comments page.
Enable preview system with comments page.
Enable archiving of old news.
Enable user management
Administration area.
Use a site template, so any changes effects the whole site.
Integrate user logins with vBulletin for custom user interface ie - if they
wanna only have general news and Quake 3 related news, then they can only
see them.
Is there a script out that does this already?
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 (Done in PHP3.0.7)
<?
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>
Can you help, or tell me a better/easier way to do this?
Also, how can I change the date from YYYY-MM-YY into a different format ?
Any help would be appreciated! :)
--James
PS - what my aim to do is to write a script that does this....
Write a site that is in PHP with a MySQL backend.
Enable news posting.
Enable review posting with rating system and comments page.
Enable preview system with comments page.
Enable archiving of old news.
Enable user management
Administration area.
Use a site template, so any changes effects the whole site.
Integrate user logins with vBulletin for custom user interface ie - if they
wanna only have general news and Quake 3 related news, then they can only
see them.
Is there a script out that does this already?