I got my register to work, with no errors but when you hit register

nothing happens, doesn’t go into database or anything. How could I fix this?

Here is my coding that you can look at if you got a suggestion.

I’m trying to link it to a page called index.php

<?php echo '
Username:
Password:
Confirm Password
    
'; ?>

here is my php code

<?php include 'connect.php'; echo '
'; echo '

Register

'; foreach($_POST as $key => $value) { $key = mysql_real_escape_string($value); } if($_SERVER['REQEUST_METHOD'] != 'POST') { include 'registerform.php'; } else { $errors = array(); if(!ctype_alnum($username)) { $errors[] = 'Your username must contain numbers and letters only!'; } if(strlen($username) > 30 || strlen($useranme) < 5) { $erros[] = 'Your username must be between 5 and 30 characters.'; } if(isset($user_password)) { if($user_password != $confirm_user_pass) { $errors[] = 'You passwords did not match!'; } } if(strlen($user_password) < 5) { $errors[] = 'Your password must be greater than 5 characters.'; } $usercheck = "SELECT username FROM Users WHERE username = '$username'"; $usercheck_query = mysql_query($usercheck); $usercheck_result = mysql_num_rows($usercheck_query); if($user_query > 0) { $errors[] = 'This username is already in use, please try again.'; } if(!empty($errors)) { echo 'Please fix the following errors:

'; echo '
    '; foreach($errors as $key => $value) { echo '
  • ' . $value . '
  • '; } echo '

'; include 'registerform.php'; } else { $cryptpass = hash_hmac('sha512', $user_password, 'asaltforthepassword'); $sql = "INSERT INTO a1146222_Users(username, user_password) VALUES('". mysql_real_escape_string($username).'" '. $cryptpass .', NOW(), 0, 0)'; $result = mysql_query($sql); if($result) { echo 'Something went wrong while registering, try again'; echo mysql_error(); include 'registerform.php'; } else { echo 'Account successfully created.'; } } } echo '
'; ?>

Firstly, try using [php] tags. It makes things easier.

Second, INSERT queries need to end in semi-colons so your query should be:

[php]
$sql = “INSERT INTO a1146222_Users (username, user_password)
VALUES(’”. mysql_real_escape_string($username).’",
‘". $cryptpass ."’,
NOW(),
0,
0);";
[/php]

The only problem here is, you have selected only 2 fields, but are trying to insert 5 Values.
So actually your code should be

[php]
$sql = “INSERT INTO a1146222_Users (username, user_password)
VALUES(’”. mysql_real_escape_string($username).’"’, “. $cryptpass .”’);";
[/php]

that doesn’t work…
it’s pretty much the same as what I had before.

I don’t understand what you mean by inserting 5 values.

Also, I programmed errors into the code, but none of the errors work

if you want to test go here

If you look at
[php]
$sql = “INSERT INTO a1146222_Users (username, user_password)
VALUES(’”. mysql_real_escape_string($username).’",
‘". $cryptpass ."’,
NOW(),
0,
0);";
[/php] You will see that you have done INSERT table (field1, field2)
VALUES (value1, value2, value3, value4, value5)

Theres an uneven amount of values.

I noticed a slight error in the second one. try
[php]
$sql = “INSERT INTO a1146222_Users (username, user_password)
VALUES(’”. mysql_real_escape_string($username)."’, “. $cryptpass .”’);";
[/php]

It still doesn’t insert into my database…
Also, none of my errors come up, I made it where let’s say your username isn’t 5 characters and you register, there is supposed to be an error, but nothing come up.

Try this code:

<?php include 'connect.php'; echo '
'; echo '

Register

'; foreach($_POST as $key => $value) { $key = mysql_real_escape_string($value); } if($_SERVER['REQEUST_METHOD'] != 'POST') { include 'registerform.php'; } else { $errors = array(); if(!ctype_alnum($username)) { $errors[] = 'Your username must contain numbers and letters only!'; } elseif(strlen($username) > 30 || strlen($useranme) < 5) { $erros[] = 'Your username must be between 5 and 30 characters.'; } elseif(isset($user_password)) { if($user_password != $confirm_user_pass) { $errors[] = 'You passwords did not match!'; } } elseif(strlen($user_password) < 5) { $errors[] = 'Your password must be greater than 5 characters.'; } $usercheck = "SELECT username FROM Users WHERE username = '$username'"; $usercheck_query = mysql_query($usercheck); $usercheck_result = mysql_num_rows($usercheck_query); elseif($user_query > 0) { $errors[] = 'This username is already in use, please try again.'; } elseif(!empty($errors)) { echo 'Please fix the following errors:

'; echo '
    '; foreach($errors as $key => $value) { echo '
  • ' . $value . '
  • '; } echo '

'; include 'registerform.php'; } else { $cryptpass = hash_hmac('sha512', $user_password, 'asaltforthepassword'); $sql = "INSERT INTO a1146222_Users (username, user_password) VALUES ('mysql_real_escape_string($username)', '$cryptpass'"; $result = mysql_query($sql); if($result) { echo 'Something went wrong while registering, try again'; echo mysql_error(); include 'registerform.php'; } else { echo 'Account successfully created.'; } } } echo '
'; ?>

[php]
if($_SERVER[‘REQEUST_METHOD’] != ‘POST’)
{
include ‘registerform.php’;
}
[/php]
Why would you do this?
It should be like
[php]
if (!isset($_POST[‘Submit’])) {
include(“registerform.php”);
}
[/php]

The way you had it checks something on the server, which is configured in the php.ini file.

@Rayth, I get a :

Parse error: syntax error, unexpected T_ELSE in /home/a1146222/public_html/register2.php on line 19

I see nothing missing either?

Can you post all of register2.php but include them in [php] tags.

[php]

<?php include 'connect.php'; echo '
'; echo '

Register

'; foreach($_POST as $key => $value) { $key = mysql_real_escape_string($value); } if (!isset($_POST['Submit'])) { include("registerform.php"); } { include 'registerform.php'; } else { $errors = array(); if(!ctype_alnum($username)) { $errors[] = 'Your username must contain numbers and letters only!'; } if(strlen($username) > 30 || strlen($useranme) < 5) { $erros[] = 'Your username must be between 5 and 30 characters.'; } if(isset($user_password)) { if($user_password != $confirm_user_pass) { $errors[] = 'You passwords did not match!'; } } if(strlen($user_password) < 5) { $errors[] = 'Your password must be greater than 5 characters.'; } $usercheck = "SELECT username FROM Users WHERE username = '$username'"; $usercheck_query = mysql_query($usercheck); $usercheck_result = mysql_num_rows($usercheck_query); if($user_query > 0) { $errors[] = 'This username is already in use, please try again.'; } if(!empty($errors)) { echo 'Please fix the following errors:

'; echo '
    '; foreach($errors as $key => $value) { echo '
  • ' . $value . '
  • '; } echo '

'; include 'registerform.php'; } else { $cryptpass = hash_hmac('sha512', $user_password, 'asaltforthepassword'); $sql = "INSERT INTO `Users` (`username`, `user_password`) VALUES('". mysql_real_escape_string($username)."', ". $cryptpass ."');"; $result = mysql_query($sql); if($result) { echo 'Something went wrong while registering, try again'; echo mysql_error(); include 'registerform.php'; } else { echo 'Account successfully created.'; } } } echo '
'; ?>

[php]

[php]

<?php include 'connect.php'; echo '
'; echo '

Register

'; foreach($_POST as $key => $value) { $key = mysql_real_escape_string($value); } if (!isset($_POST['Submit'])) { include("registerform.php"); } { include 'registerform.php'; } else { $errors = array(); if(!ctype_alnum($username)) { $errors[] = 'Your username must contain numbers and letters only!'; } if(strlen($username) > 30 || strlen($useranme) < 5) { $erros[] = 'Your username must be between 5 and 30 characters.'; } if(isset($user_password)) { if($user_password != $confirm_user_pass) { $errors[] = 'You passwords did not match!'; } } if(strlen($user_password) < 5) { $errors[] = 'Your password must be greater than 5 characters.'; } $usercheck = "SELECT username FROM Users WHERE username = '$username'"; $usercheck_query = mysql_query($usercheck); $usercheck_result = mysql_num_rows($usercheck_query); if($user_query > 0) { $errors[] = 'This username is already in use, please try again.'; } if(!empty($errors)) { echo 'Please fix the following errors:

'; echo '
    '; foreach($errors as $key => $value) { echo '
  • ' . $value . '
  • '; } echo '

'; include 'registerform.php'; } else { $cryptpass = hash_hmac('sha512', $user_password, 'asaltforthepassword'); $sql = "INSERT INTO `Users` (`username`, `user_password`) VALUES('". mysql_real_escape_string($username)."', ". $cryptpass ."');"; $result = mysql_query($sql); if($result) { echo 'Something went wrong while registering, try again'; echo mysql_error(); include 'registerform.php'; } else { echo 'Account successfully created.'; } } } echo '
'; ?>

[/php]

[php]

<?php include 'connect.php'; echo '
'; echo '

Register

'; foreach($_POST as $key => $value) { $key = mysql_real_escape_string($value); } if (!isset($_POST['Submit'])) { include("registerform.php"); } else { $errors = array(); if(!ctype_alnum($username)) { $errors[] = 'Your username must contain numbers and letters only!'; } if(strlen($username) > 30 || strlen($useranme) < 5) { $erros[] = 'Your username must be between 5 and 30 characters.'; } if(isset($user_password)) { if($user_password != $confirm_user_pass) { $errors[] = 'You passwords did not match!'; } } if(strlen($user_password) < 5) { $errors[] = 'Your password must be greater than 5 characters.'; } $usercheck = "SELECT username FROM Users WHERE username = '$username'"; $usercheck_query = mysql_query($usercheck); $usercheck_result = mysql_num_rows($usercheck_query); if($user_query > 0) { $errors[] = 'This username is already in use, please try again.'; } if(!empty($errors)) { echo 'Please fix the following errors:

'; echo '
    '; foreach($errors as $key => $value) { echo '
  • ' . $value . '
  • '; } echo '

'; include 'registerform.php'; } else { $cryptpass = hash_hmac('sha512', $user_password, 'asaltforthepassword'); $sql = "INSERT INTO `Users` (`username`, `user_password`) VALUES('". mysql_real_escape_string($username)."', ". $cryptpass ."');"; $result = mysql_query($sql); if($result) { echo 'Something went wrong while registering, try again'; echo mysql_error(); include 'registerform.php'; } else { echo 'Account successfully created.'; } } } echo '
'; ?>

[/php]
Removed the error you mentioned.

When I click register with all the correct info, it gives me errors just plain out.
Like I have a username greater than 5
Password greater than 5

but I still get the errors randomly.

[php]
if(strlen($username) > 30 || strlen($useranme) < 5)
[/php]
Spelling mistake? check the rest as well to make sure.

Nope, still get the errors
do you want to test it to see what I mean?

Can anyone else help?

Sponsor our Newsletter | Privacy Policy | Terms of Service