Zymic Forums

Webmaster resources

Zymic IRC Server

Chat in real time at irc.zymic.com - Learn More

Welcome

Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.

In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.

left Zymic Webmaster ForumsZymic Free Web HostingZymic Free Web Hosting - General Discussion & Help right
  Reply to this topic Start new topic
left right
Larabeast
post Jun 19 2011, 07:51 AM
Post #1


Newbie
*

Group: Members
Posts: 17
Joined: 15-June 11
Member No.: 194,389



Okay, I'm going by the tutorial on how to make a login and register page, everything works fine EXCEPT, when you click submit your info it doesn't put anything in the database or give an error (It's supposed to give errors if it doesn't successfully register and log the info in the database) but it's not doing anything but taking me back to the index. http://gamingprodigies.zymichost.com/ I think something is wrong with this code because EVERYTHING else works.

CODE
<?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.');
    }
    //validate the inputs
    $_POST['uname'] = safe($_POST['uname']);
    $_POST['passwd'] = safe($_POST['passwd']);
    $_POST['email'] = safe($_POST['email']);
    $_POST['website'] = safe($_POST['website']);
    $_POST['location'] = safe($_POST['location']);
    // check if username exists in database.
    $qry = "SELECT username FROM users WHERE username = '".$_POST['uname']."'";
                $sqlmembers = mysql_query($qry);
                $name_check = mysql_fetch_array ($sqlmembers);
                $name_checkk = mysql_num_rows ($sqlmembers);
    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.');
    }
    // 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. */
    
    // now we can add them to the database.
    // encrypt password
    $_POST['passwd'] = sha1($salt.$_POST['passwd']);
    $regdate = date('m d, Y');
    $insert = "INSERT INTO users (
            username,
            password,
            regdate,
            email,
            website,
            location,
            show_email)
            VALUES (
            '".$_POST['uname']."',
            '".$_POST['passwd']."',
            '$regdate',
            '".$_POST['email']."',
            '".$_POST['website']."',
            '".$_POST['location']."',
            '".$_POST['show_email']."')";

    $sqlmembers = mysql_query($insert);
?>
<h1>Registered</h1>
<p>Thank you, your information has been added to the database,
you may now <a href="login.php" title="Login">log in</a>.</p>
<?php
} else {    // if form hasn't been submitted
?>
<h1>Register</h1>
<form action="index.php?id=register" 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>Website:</td><td>
<input type="text" name="website" maxlength="150">
</td></tr>
<tr><td>Location</td><td>
<input type="text" name="location" maxlength="150">
</td></tr>
<tr><td>Show E-Mail?</td><td>
<select name="show_email">
<option value="1" selected="selected">Yes</option>
<option value="0">No</option></select>
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Sign Up">
</td></tr>
</table>
</form>
<?php
}
?>
Go to the top of the page 
 
  + Quote Post
Ratneer
post Jun 20 2011, 12:24 PM
Post #2


Newbie
*

Group: Members
Posts: 19
Joined: 21-January 11
Member No.: 174,147



Uhm.. If this is your entire code, and your not including any of files.. there are a few things wrong.

1. There is no database connection.
2. the function safe() is undefined.
3. You haven't set a salt in $salt.

Honestly, it seems you are trying to run website when you have very little knowledge of php. Try going to w3schools or php.net and brush up on it, or you will never get it right and be stuck asking for help your entire coding career.
Go to the top of the page 
 
  + Quote Post
Larabeast
post Jun 20 2011, 04:11 PM
Post #3


Newbie
*

Group: Members
Posts: 17
Joined: 15-June 11
Member No.: 194,389



You seem to not know what I'm talking about? Why would I post other files when EVERY other aspect works just fine, you're false assumptions are very appalling, why would I need to post login.php, logout,php, and everything else when EVERYTHING else is flawless? I'm not a dumbass, I know what's having a problem WHEN it's having a problem.
Go to the top of the page 
 
  + Quote Post
Ratneer
post Jun 23 2011, 05:16 PM
Post #4


Newbie
*

Group: Members
Posts: 19
Joined: 21-January 11
Member No.: 174,147



If you want proper help, you need to post ALL aspects of the problem. How can you honestly expect any help when we don't know everything about the situation?

You need to learn some basic debugging skills; add die() to all of your queries, and start echoing back ALL of your variables, and even echo out some of the if statements to see if they are failing.

So don't call my assumptions false when you don't have enough sense to at least try and fix it yourself. There will not be someone there your entire life to help you, so you need to learn how to do it right yourself. I don't have to be here trying to help you, no one does, so why not try to be a bit nicer when asking for others help?
Go to the top of the page 
 
  + Quote Post
 Reply to this topic Start new topic
left right
0 Members:
left right
 


Lo-Fi Version Time is now: 18th May 2013 - 12:11 PM