Need help with PHP script that is not working

  • thomas_sum
  • Beginner
  • Beginner
  • thomas_sum
  • Posts: 44

Post 3+ Months Ago

Quote:
<?php
require('db_connect.php'); // database connect script.
?>

<html>
<head>
<title>Register an Account</title>
</head>
<body>

<?php

if (isset($_POST['submit'])) { // if form has been submitted
/* check they filled in what they supposed to,
passwords matched, username
isn't already taken, etc. */

if (!$_POST['uname'] | !$_POST['passwd'] | !$_POST['passwd_again'] | !$_POST['email']) {
die('You did not fill in a required field.');
}

// check if username exists in database.

if (!get_magic_quotes_gpc()) {
$_POST['uname'] = addslashes($_POST['uname']);
}



$name_check = $db_object->query("SELECT username FROM users WHERE username = '".$_POST['uname']."'");

if (DB::isError($name_check)) {
die($name_check->getMessage());
}

$name_checkk = $name_check->numRows();

if ($name_checkk != 0) {
die('Sorry, the username: <strong>'.$_POST['uname'].'</strong> is already taken, please pick another one.');
}

// check passwords match

if ($_POST['passwd'] != $_POST['passwd_again']) {
die('Passwords did not match.');
}

// check e-mail format

if (!preg_match("/.*@.*..*/", $_POST['email']) | preg_match("/(<|>)/", $_POST['email'])) {
die('Invalid e-mail address.');
}

// no HTML tags in username, website, location, password

$_POST['uname'] = strip_tags($_POST['uname']);
$_POST['passwd'] = strip_tags($_POST['passwd']);
$_POST['website'] = strip_tags($_POST['website']);
$_POST['location'] = strip_tags($_POST['location']);



// check show_email data

if ($_POST['show_email'] != 0 & $_POST['show_email'] != 1) {
die('Nope');
}

/* the rest of the information is optional, the only thing we need to
check is if they submitted a website,
and if so, check the format is ok. */

if ($_POST['website'] != '' & !preg_match("/^(http|ftp):\/\//", $_POST['website'])) {
$_POST['website'] = 'http://'.$_POST['website'];
}

// now we can add them to the database.
// encrypt password

$_POST['passwd'] = md5($_POST['passwd']);

if (!get_magic_quotes_gpc()) {
$_POST['passwd'] = addslashes($_POST['passwd']);
$_POST['email'] = addslashes($_POST['email']);
$_POST['website'] = addslashes($_POST['website']);
$_POST['location'] = addslashes($_POST['location']);
}



$regdate = date('m d, Y');

$insert = "INSERT INTO users (
username,
password,
regdate,
email,
website,
location,
show_email,
last_login)
VALUES (
'".$_POST['uname']."',
'".$_POST['passwd']."',
'$regdate',
'".$_POST['email']."',

'Never')";

$add_member = $db_object->query($insert);

if (DB::isError($add_member)) {
die($add_member->getMessage());
}

$db_object->disconnect();
?>
</h1>
<h1>Registered</h1>

<p>Thank you, your information has been added to the database, you may now <a href="login2.php" title="Login">log in</a>.</p>

<?php

} else { // if form hasn't been submitted

?>
<h1>Register</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr>
<td>Username*:</td>
<td> <input type="text" name="uname" maxlength="40"> </td>
</tr>
<tr>
<td>Password*:</td>
<td> <input type="password" name="passwd" maxlength="50"> </td>
</tr>
<tr>
<td>Confirm Password*:</td>
<td> <input type="password" name="passwd_again" maxlength="50"> </td>
</tr>
<tr>
<td>E-Mail*:</td>
<td> <input type="text" name="email" maxlength="100"> </td>
</tr>
<tr>
<td colspan="2" align="right"> <input type="submit" name="submit" value="Sign Up">
</td>
</tr>
</table>
</form>

<?php

}

?>
</body>
</html>



I need help for the above script.... When i preview in the broswer, the coding appear in it.... Can someone help me to see the script wat went wrong.... thanks in advance and sorry to trouble any of you guys!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

do you have an example? One thing that seems wrong are your "or" operators they should be "||" not "|".
  • thomas_sum
  • Beginner
  • Beginner
  • thomas_sum
  • Posts: 44

Post 3+ Months Ago

i do not have any example... But i found this script from this site.....

http://www.free2code.net/tutorials/programming/php/4/phplogin.php
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

It sounds like the server isn't preprocessing the file for scripts at all. Do you have any other php scripts running on the same server that are working properly? If that's the only script you've tried on this server, try another one that you know works and see what happens. If the server has php installed and it is working properly, make sure the file extension is "php" and not "html" or "htm". The server won't check the file for scripts if it doesn't find the right extension.
  • tierra
  • Student
  • Student
  • User avatar
  • Posts: 91

Post 3+ Months Ago

It's really not the fact that the extension is .php, but it also has to be configured in Apache or whatever browser you have to run .php files through PHP.
  • thomas_sum
  • Beginner
  • Beginner
  • thomas_sum
  • Posts: 44

Post 3+ Months Ago

These script was pasted in dreamweaver and was saved as register.php. I do not any server but i have downloaded the microsoft sql. But the sql cant work..... I now very confused and didnt know wat to do now :(
i m very new to php also...
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

So did you try using another basic script in php on your server to just see if that works?
  • thomas_sum
  • Beginner
  • Beginner
  • thomas_sum
  • Posts: 44

Post 3+ Months Ago

Yup! others basic php script does work... Just this login script wont work... i even downloaded a login javascript and it worked... maybe you guys can show me where to get good login script that able user to register and login... thanks a million! :)

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 162 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.