By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

DB User authentication.

P: n/a
Not a programmin newbie, but a PHP newbie.

I'm working off the user authentication and database thing off
hotscripts.com.

It doesn't work, yet from what I can see, it should.

Maybe I've done something wrong (no wait... obviously I've done something
wrong)

Any help?
Here are the contents of the relevant files:

INDEX.HTML:
<form name="form1" method="post" action="register.php">
<p>First Name
<input name="first_name" type="text" id="first_name" value="">
<br>
Last Name
<input type="text" name="last_name" value="">
<br>
Email Address:
<input type="text" name="email_address" value="">
<br>
Username:
<input type="text" name="username" value="">
<br>
Info:
<textarea name="info"></textarea>
<br>
<input type="submit" name="Submit" value="Join">
</p>
</form>

REGISTER.PHP

<?
include 'db.php';

//define variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);

echo $first_name . "<br>";
echo $last_name . "<br>";
echo $email_address . "<br>";
echo $username . "<br>";
echo $info . "<br>";

/* if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br
/>";
}
if(!$username){
echo "Desired Username is a required field. Please enter it
below.<br />";
}
include 'index.html'; // Show the form again!
exit(); // if the error checking has failed, we'll exit the script!
}*/

$sql_email_check = mysql_query("SELECT email_address FROM users WHERE
email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE
username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if($email_check > 0 || $username_check > 0) {
echo "There were some errors: <br>";
if($email_check > 0) {
echo "email taken";
unset($email_address);
}
if($username_check > 0) {
echo "username taken";
unset($username);
}
include 'index.html';
exit();
}

function makeRandomPassword() {
$salt = "abcdefghijklmnopqrstuvwxyz1234567890";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pas = $pass . $tmp;
$i++
}
return $pass;
}

$random_password = makeRandomPassword();

$db_password = md5($random_password);

$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address,
username, password, info, signup_date) VALUES ('$first_name, $last_name,
$email_address, $username, $password, $info2, now())" or die
(mysql_error());

if ($sql) {
echo "bugger";
} else {
$userid = mysql_insert_id();
$subject = "membership, foo";
$message = "Dear $first_namae $last_name,
To activate you membership, click here:
http://[[domain]]/dbtest/activate.php?id=$userid&amp;code=$db_password
Thanks!";
mail($email_address, $subject, $message, 'From: Yep-MM test Server\n
X-Mailer: PHP/' . phpversion());
echo "Done.";
}
?>

DB.PHP
<?
$hostname = "localhost";
$database = "[[dbname]]";
$username = "[[username]]";
$password = "[[password]]";
$connection = mysql_pconnect($hostname, $username, $password) or
die(mysql_error());
?>
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Allan Hugo wrote:

Not a programmin newbie, but a PHP newbie.

I'm working off the user authentication and database thing off
hotscripts.com.

It doesn't work, yet from what I can see, it should.

Maybe I've done something wrong (no wait... obviously I've done something
wrong)

Any help?
Here are the contents of the relevant files:

INDEX.HTML:
<form name="form1" method="post" action="register.php">
<p>First Name
<input name="first_name" type="text" id="first_name" value="">
<br>
Last Name
<input type="text" name="last_name" value="">
<br>
Email Address:
<input type="text" name="email_address" value="">
<br>
Username:
<input type="text" name="username" value="">
<br>
Info:
<textarea name="info"></textarea>
<br>
<input type="submit" name="Submit" value="Join">
</p>
</form>

REGISTER.PHP

<?
include 'db.php';

//define variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);

echo $first_name . "<br>";
echo $last_name . "<br>";
echo $email_address . "<br>";
echo $username . "<br>";
echo $info . "<br>";

/* if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){
echo 'You did not submit the following required information! <br />';
if(!$first_name){
echo "First Name is a required field. Please enter it below.<br />";
}
if(!$last_name){
echo "Last Name is a required field. Please enter it below.<br />";
}
if(!$email_address){
echo "Email Address is a required field. Please enter it below.<br
/>";
}
if(!$username){
echo "Desired Username is a required field. Please enter it
below.<br />";
}
include 'index.html'; // Show the form again!
exit(); // if the error checking has failed, we'll exit the script!
}*/

$sql_email_check = mysql_query("SELECT email_address FROM users WHERE
email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE
username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if($email_check > 0 || $username_check > 0) {
echo "There were some errors: <br>";
if($email_check > 0) {
echo "email taken";
unset($email_address);
}
if($username_check > 0) {
echo "username taken";
unset($username);
}
include 'index.html';
exit();
}

function makeRandomPassword() {
$salt = "abcdefghijklmnopqrstuvwxyz1234567890";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pas = $pass . $tmp;
$i++
}
return $pass;
}

$random_password = makeRandomPassword();

$db_password = md5($random_password);

$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name, email_address,
username, password, info, signup_date) VALUES ('$first_name, $last_name,
$email_address, $username, $password, $info2, now())" or die
(mysql_error());

if ($sql) {
echo "bugger";
} else {
$userid = mysql_insert_id();
$subject = "membership, foo";
$message = "Dear $first_namae $last_name,
To activate you membership, click here:
http://[[domain]]/dbtest/activate.php?id=$userid&amp;code=$db_password
Thanks!";
mail($email_address, $subject, $message, 'From: Yep-MM test Server\n
X-Mailer: PHP/' . phpversion());
echo "Done.";
}
?>

DB.PHP
<?
$hostname = "localhost";
$database = "[[dbname]]";
$username = "[[username]]";
$password = "[[password]]";
$connection = mysql_pconnect($hostname, $username, $password) or
die(mysql_error());
?>


What do you mean by "doesn't work"? Please describe any error messages you're
getting, or other indications that it is not working correctly.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2

P: n/a

"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:3F***************@glassgiant.com...
Allan Hugo wrote:

Not a programmin newbie, but a PHP newbie.

I'm working off the user authentication and database thing off
hotscripts.com.

It doesn't work, yet from what I can see, it should.

Maybe I've done something wrong (no wait... obviously I've done something wrong)

Any help? <snip>

What do you mean by "doesn't work"? Please describe any error messages you're getting, or other indications that it is not working correctly.


what do i mean by 'doesn't work'?

well i get a white page...
Jul 17 '05 #3

P: n/a
On Tue, 04 Nov 2003 00:07:26 GMT, Allan Hugo wrote:

"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:3F***************@glassgiant.com...
Allan Hugo wrote:

Not a programmin newbie, but a PHP newbie.

I'm working off the user authentication and database thing off
hotscripts.com.

It doesn't work, yet from what I can see, it should.

Maybe I've done something wrong (no wait... obviously I've done something wrong)

Any help?

<snip>

What do you mean by "doesn't work"? Please describe any error messages

you're
getting, or other indications that it is not working correctly.


what do i mean by 'doesn't work'?

well i get a white page...


what do i mean by 'try and help yourself a little more'?

Try using the same debug process that you do in any other language.
Add some echo commands to see where the process is failing, and ask
something a little more specific than "please debug my whole program" :)

Cheers,
iGadget
Jul 17 '05 #4

P: n/a
In article <9T*********************@news-server.bigpond.net.au>,
so*****@microsoft.com says...
Not a programmin newbie, but a PHP newbie.

I'm working off the user authentication and database thing off
hotscripts.com.

It doesn't work, yet from what I can see, it should.
Can you be a little more specific about 'doesn't work' - do you mean it
lays on the couch all day drinking beer? Or is there some sort of error
message? Or...
Maybe I've done something wrong (no wait... obviously I've done something
wrong)

Any help?
Here are the contents of the relevant files:

INDEX.HTML:

<SNIP> lots of code
As a debugging aid, you might consider using mysql_error after all calls
to the db, and also echo your queries to ensure you are submitting the
query you think you are.

Cheers
--
Quod subigo farinam

$email =~ s/oz$/au/o;
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.