Jump to content

Registration not working?


localhost

Recommended Posts

Here is my user registration script that I am making from scratch, I am new to PHP btw.

[code]
<?php

include('inc/connect.php');


$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$cpass = $_POST['cpass'];
$aim = $_POST['aim'];
$msn = $_POST['msn'];
$yim = $_POST['yim'];
$priv = $_POST['priv'];
$regip = $_POST['regip'];
$regdate = $_POST['regdate'];

if($pass!=$cpass) {
echo "Passwords must match.";
} else {
$query = ("INSERT INTO `users` (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')");
$result = @mysql_query($query)
        or die("There was a problem with this query:".mysql_error());
}


?>

<form action="" method="POST"> * Indicates a required field
<p>
  <input type="hidden" name="priv" value="1" />
  <input type="hidden" name="regip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> " />
  <input type="hidden" name="regdate" value=" <?php echo date('d/m/y'); ?> " />
  *Username:
  <input type="text" name="username" value="" />
  <BR>
  *eMail:
  <input type="text" name="email" value="">
  <Br>
  *Password:
  <input type="password" name="pass" value="">
  <Br>
  *Confirm Password:
  <input type="password" name="cpass" value="">
  <Br>
  AIM:
  <input type="text" name="aim" value="">
  <BR>
  MSN:
  <input type="text" name="msn" value="">
  <br>
  YIM:
  <input type="text" name="yim" value="">
  <Br>
  <input type="submit" name="submit" value="Register">
</p>

[/code]

It comes up with this error:

There was a problem with this query:Column count doesn't match value count at row 1

Not sure how to fix it, also I will be asking once I get this fixed and once it starts writing to the database, how I can secure the script and such, also I know it doesn't use any encryption at all, I want it working before I add the md5.

Thanks for any help you may be able to provide!
Link to comment
Share on other sites

change your query.

have ALL the fields in the table listed in the fields of teh query and those where no value should be inserted simply have '' in coreesponding values position.

Assuming the only field you have omitted is the unique id and that has autoincrement... do this

$query = ("INSERT INTO `users` (`unique_id`, `username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('', '$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')");

Now some other help for you....

comparing strings - use the strcomp functions instead.

checking user input: use mysql_real_escape_string to prevent mysql injection.

use the sha1 instead of md5 - its just a bit better IMO.
Link to comment
Share on other sites

[!--quoteo(post=377814:date=May 28 2006, 11:22 PM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 11:22 PM) [snapback]377814[/snapback][/div][div class=\'quotemain\'][!--quotec--]
As I said, I am completely new to PHP, I have no idea what you are talking about in alot of that, I just replaced my query with the one you posted and I still get the same error.

Also, is sha1 built into php like md5?
[/quote]


He means you have to replace the "unique_id" field with your unique id field... Like userID or ID.


Get a description of your table. If you use phpMyAdmin, find the table, go SQL and put in "describe yourtablename" replacing yourtablename with the name of the table.

If you use a command line client (where it says mysql>), put in "use yourdatabase;" and "describe yourtablename;", replacing the relevant bits with your data.



/Whitey
Link to comment
Share on other sites

I did replace unique_id with just "id".
Which is what it is called. Here is the sql query I used for the script:

[code]

CREATE TABLE users (  
           id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,  
           username VARCHAR(255) NOT NULL,
       email VARCHAR(255) NOT NULL,
       pass VARCHAR(32) NOT NULL,  
           aim VARCHAR(255) NOT NULL,
       msn VARCHAR(255) NOT NULL,
       yim VARCHAR(255) NOT NULL,
       priv VARCHAR(255) NOT NULL,  
           regip VARCHAR(255) NOT NULL,  
           regdate VARCHAR(255) NOT NULL
           )  
           TYPE = myisam;
[/code]
Link to comment
Share on other sites

[!--quoteo(post=377808:date=May 28 2006, 07:54 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 07:54 AM) [snapback]377808[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Here is my user registration script that I am making from scratch, I am new to PHP btw.

[code]
<?php

include('inc/connect.php');
$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$cpass = $_POST['cpass'];
$aim = $_POST['aim'];
$msn = $_POST['msn'];
$yim = $_POST['yim'];
$priv = $_POST['priv'];
$regip = $_POST['regip'];
$regdate = $_POST['regdate'];

if($pass!=$cpass) {
echo "Passwords must match.";
} else {
$query = ("INSERT INTO `users` (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')");
$result = @mysql_query($query)
        or die("There was a problem with this query:".mysql_error());
}
?>

<form action="" method="POST"> * Indicates a required field
<p>
  <input type="hidden" name="priv" value="1" />
  <input type="hidden" name="regip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> " />
  <input type="hidden" name="regdate" value=" <?php echo date('d/m/y'); ?> " />
  *Username:
  <input type="text" name="username" value="" />
  <BR>
  *eMail:
  <input type="text" name="email" value="">
  <Br>
  *Password:
  <input type="password" name="pass" value="">
  <Br>
  *Confirm Password:
  <input type="password" name="cpass" value="">
  <Br>
  AIM:
  <input type="text" name="aim" value="">
  <BR>
  MSN:
  <input type="text" name="msn" value="">
  <br>
  YIM:
  <input type="text" name="yim" value="">
  <Br>
  <input type="submit" name="submit" value="Register">
</p>

[/code]

It comes up with this error:

There was a problem with this query:Column count doesn't match value count at row 1

Not sure how to fix it, also I will be asking once I get this fixed and once it starts writing to the database, how I can secure the script and such, also I know it doesn't use any encryption at all, I want it working before I add the md5.

Thanks for any help you may be able to provide!
[/quote]


change this
[code]$query = ("INSERT INTO `users` (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')");[/code]

to this
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";

or this
$query = "INSERT INTO `users` VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";


if your filling out all the spots in the database yiou can use the third one...but i dont know what your database looks likes
Link to comment
Share on other sites

With this one:

$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";

I still get the same error...present here:
[a href=\"http://www.thecodingplace.com/dl/usersystem/register.php\" target=\"_blank\"]http://www.thecodingplace.com/dl/usersystem/register.php[/a]
Link to comment
Share on other sites

[!--quoteo(post=377830:date=May 28 2006, 09:33 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 09:33 AM) [snapback]377830[/snapback][/div][div class=\'quotemain\'][!--quotec--]
With this one:

$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email' '$pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";

I still get the same error...present here:
[a href=\"http://www.thecodingplace.com/dl/usersystem/register.php\" target=\"_blank\"]http://www.thecodingplace.com/dl/usersystem/register.php[/a]
[/quote]

in values put the comma inbetween 'email' and 'pass' thats likly your problem...or make sure all the colunms in the users are spelt excaxtly the same as youve put them (CAPS too)
Link to comment
Share on other sites

Works perfectly and writes to the database! Thanks alot, I didn't even notice there wasn't a comma in between email and pass. I have even got sha1 working.

Is there a way to make it so when they hit register, it takes them to a different page?

And how would I do a statement like if username exists state an error message saying this user already exists.

This is my current code:

[code]
<?php

include('inc/connect.php');


$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$cpass = $_POST['cpass'];
$aim = $_POST['aim'];
$msn = $_POST['msn'];
$yim = $_POST['yim'];
$priv = $_POST['priv'];
$regip = $_POST['regip'];
$regdate = $_POST['regdate'];

$sec_pass = sha1('$pass');

if($pass!=$cpass) {
echo "Passwords must match.";
} else {
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email', '$sec_pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";
$result = @mysql_query($query)
        or die("There was a problem with this query: ".mysql_error());
}


?>

<form action="" method="POST"> * Indicates a required field
<p>
  <input type="hidden" name="priv" value="1" />
  <input type="hidden" name="regip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> " />
  <input type="hidden" name="regdate" value=" <?php echo date('m/d/y'); ?> " />
  *Username:
  <input type="text" name="username" value="" />
  <BR>
  *eMail:
  <input type="text" name="email" value="">
  <Br>
  *Password:
  <input type="password" name="pass" value="">
  <Br>
  *Confirm Password:
  <input type="password" name="cpass" value="">
  <Br>
  AIM:
  <input type="text" name="aim" value="">
  <BR>
  MSN:
  <input type="text" name="msn" value="">
  <br>
  YIM:
  <input type="text" name="yim" value="">
  <Br>
  <input type="submit" name="submit" value="Register">
</p>
[/code]
Link to comment
Share on other sites

[!--quoteo(post=377834:date=May 28 2006, 09:47 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 09:47 AM) [snapback]377834[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Works perfectly and writes to the database! Thanks alot, I didn't even notice there wasn't a comma in between email and pass. I have even got sha1 working.

Is there a way to make it so when they hit register, it takes them to a different page?

And how would I do a statement like if username exists state an error message saying this user already exists.

This is my current code:

[code]
<?php

include('inc/connect.php');
$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$cpass = $_POST['cpass'];
$aim = $_POST['aim'];
$msn = $_POST['msn'];
$yim = $_POST['yim'];
$priv = $_POST['priv'];
$regip = $_POST['regip'];
$regdate = $_POST['regdate'];

$sec_pass = sha1('$pass');

if($pass!=$cpass) {
echo "Passwords must match.";
} else {
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email', '$sec_pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";
$result = @mysql_query($query)
        or die("There was a problem with this query: ".mysql_error());
}
?>

<form action="" method="POST"> * Indicates a required field
<p>
  <input type="hidden" name="priv" value="1" />
  <input type="hidden" name="regip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> " />
  <input type="hidden" name="regdate" value=" <?php echo date('m/d/y'); ?> " />
  *Username:
  <input type="text" name="username" value="" />
  <BR>
  *eMail:
  <input type="text" name="email" value="">
  <Br>
  *Password:
  <input type="password" name="pass" value="">
  <Br>
  *Confirm Password:
  <input type="password" name="cpass" value="">
  <Br>
  AIM:
  <input type="text" name="aim" value="">
  <BR>
  MSN:
  <input type="text" name="msn" value="">
  <br>
  YIM:
  <input type="text" name="yim" value="">
  <Br>
  <input type="submit" name="submit" value="Register">
</p>
[/code]
[/quote]

to move to a new locattion put this

header("Location: page.php");

but make sure the <?PHP is the very first thing at the stop of your page! no <html> before it...or else there will be an error saying headers already sent....

to find if username alrady exist make a new query and result then

while($row = mysql_fletch_array(result2)){
if($username == $row['username']){
do this
}
Link to comment
Share on other sites

Kind of like this?

[code]

<?php

include('inc/connect.php');


$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$cpass = $_POST['cpass'];
$aim = $_POST['aim'];
$msn = $_POST['msn'];
$yim = $_POST['yim'];
$priv = $_POST['priv'];
$regip = $_POST['regip'];
$regdate = $_POST['regdate'];

$invalid = "";

$sec_pass = sha1('$pass');

if($pass!=$cpass || $username==$invalid || $email==$invalid || $pass==$invalid || $cpass==$invalid) {
echo "<font color=red>ERROR: Make sure all fields marked with a * are filled, and that your username and password match.</font><BR>";
} else {
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email', '$sec_pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";
$result = @mysql_query($query)
        or die("There was a problem with this query: ".mysql_error());
}

$uquery = while($row = mysql_fetch_array(result2)){
if($username == $row['username']){
echo "Username already taken.";
}
$result = mysql_query($uquery) or die('Username query could not be executed');

header("Location: http://www.google.com");
?>

<form action="" method="POST"> * Indicates a required field
<p>
  <input type="hidden" name="priv" value="1" />
  <input type="hidden" name="regip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> " />
  <input type="hidden" name="regdate" value=" <?php echo date('m/d/y'); ?> " />
  *Username:
  <input type="text" name="username" value="" />
  <BR>
  *eMail:
  <input type="text" name="email" value="">
  <Br>
  *Password:
  <input type="password" name="pass" value="">
  <Br>
  *Confirm Password:
  <input type="password" name="cpass" value="">
  <Br>
  AIM:
  <input type="text" name="aim" value="">
  <BR>
  MSN:
  <input type="text" name="msn" value="">
  <br>
  YIM:
  <input type="text" name="yim" value="">
  <Br>
  <input type="submit" name="submit" value="Register">
</p>

[/code]

That gives me this error:
Parse error: parse error, unexpected T_WHILE in /home/tcp/public_html/dl/usersystem/register.php on line 30

P.S. - sorry for asking for so much help, I just really want to get some php experience.
Link to comment
Share on other sites

[!--quoteo(post=377845:date=May 28 2006, 10:09 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 10:09 AM) [snapback]377845[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Kind of like this?

[code]

<?php

include('inc/connect.php');
$username = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$cpass = $_POST['cpass'];
$aim = $_POST['aim'];
$msn = $_POST['msn'];
$yim = $_POST['yim'];
$priv = $_POST['priv'];
$regip = $_POST['regip'];
$regdate = $_POST['regdate'];

$invalid = "";

$sec_pass = sha1('$pass');

if($pass!=$cpass || $username==$invalid || $email==$invalid || $pass==$invalid || $cpass==$invalid) {
echo "<font color=red>ERROR: Make sure all fields marked with a * are filled, and that your username and password match.</font><BR>";
} else {
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email', '$sec_pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";
$result = @mysql_query($query)
        or die("There was a problem with this query: ".mysql_error());
}

$uquery = while($row = mysql_fetch_array(result2)){
if($username == $row['username']){
echo "Username already taken.";
}
$result = mysql_query($uquery) or die('Username query could not be executed');

header("Location: http://www.google.com");
?>

<form action="" method="POST"> * Indicates a required field
<p>
  <input type="hidden" name="priv" value="1" />
  <input type="hidden" name="regip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> " />
  <input type="hidden" name="regdate" value=" <?php echo date('m/d/y'); ?> " />
  *Username:
  <input type="text" name="username" value="" />
  <BR>
  *eMail:
  <input type="text" name="email" value="">
  <Br>
  *Password:
  <input type="password" name="pass" value="">
  <Br>
  *Confirm Password:
  <input type="password" name="cpass" value="">
  <Br>
  AIM:
  <input type="text" name="aim" value="">
  <BR>
  MSN:
  <input type="text" name="msn" value="">
  <br>
  YIM:
  <input type="text" name="yim" value="">
  <Br>
  <input type="submit" name="submit" value="Register">
</p>

[/code]

That gives me this error:
Parse error: parse error, unexpected T_WHILE in /home/tcp/public_html/dl/usersystem/register.php on line 30

P.S. - sorry for asking for so much help, I just really want to get some php experience.
[/quote]

the query has to be proper so like this

$query2 = "SELECT * FROM table";
$result2 = @mysql_query($query2);

then the While statement underneath

P.S the best way to gain experiance is to buy a good book! I would recommend "PHP and MySQL for dynamic web sites Second edition" By Larry Ullman
THats what got me going
Link to comment
Share on other sites

Took a small part this time:

[code]
if($pass!=$cpass || $username==$invalid || $email==$invalid || $pass==$invalid || $cpass==$invalid) {
echo "<font color=red>ERROR: Make sure all fields marked with a * are filled, and that your username and password match.</font><BR>";
} else {
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email', '$sec_pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";
$result = @mysql_query($query)
        or die("There was a problem with this query: ".mysql_error());
}

$query2 = "SELECT * FROM `users`";
$result2 = mysql_query($query2) or die('Username query could not be executed');
while($row = mysql_fetch_array(result2)){
if($username == $row['username']){
echo "Username already taken.";
}


header("Location: http://www.google.com");
?>
[/code]

And you can see the error here:
[a href=\"http://www.thecodingplace.com/dl/usersystem/register.php\" target=\"_blank\"]http://www.thecodingplace.com/dl/usersystem/register.php[/a]

Line 68 is just </p>

Anyway about the book, I might buy one soon...I just need to get some cash.
Link to comment
Share on other sites

[!--quoteo(post=377851:date=May 28 2006, 10:32 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 10:32 AM) [snapback]377851[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Took a small part this time:

[code]
if($pass!=$cpass || $username==$invalid || $email==$invalid || $pass==$invalid || $cpass==$invalid) {
echo "<font color=red>ERROR: Make sure all fields marked with a * are filled, and that your username and password match.</font><BR>";
} else {
$query = "INSERT INTO users (`username`, `email`, `pass`, `aim`, `msn`, `yim`, `priv`, `regip`, `regdate`)
VALUES ('$username', '$email', '$sec_pass', '$aim', '$msn', '$yim', '$priv', '$regip', '$regdate')";
$result = @mysql_query($query)
        or die("There was a problem with this query: ".mysql_error());
}

$query2 = "SELECT * FROM `users`";
$result2 = mysql_query($query2) or die('Username query could not be executed');
while($row = mysql_fetch_array(result2)){
if($username == $row['username']){
echo "Username already taken.";
}
header("Location: http://www.google.com");
?>
[/code]

And you can see the error here:
[a href=\"http://www.thecodingplace.com/dl/usersystem/register.php\" target=\"_blank\"]http://www.thecodingplace.com/dl/usersystem/register.php[/a]

Line 68 is just </p>

Anyway about the book, I might buy one soon...I just need to get some cash.
[/quote]

add a } after header();
Link to comment
Share on other sites

[!--quoteo(post=377856:date=May 28 2006, 10:56 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 10:56 AM) [snapback]377856[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ugh so frustrating! I added a } after the header part but now I get this:

[a href=\"http://www.thecodingplace.com/dl/usersystem/register.php\" target=\"_blank\"]http://www.thecodingplace.com/dl/usersystem/register.php[/a]
[/quote]

lol...ok in the while statement change array to row so

while ($row = mysql_fletch_row(result2)){
}

also to retreave the info

$row[3] but replace 3 with proper number!

thats the only thing i can think off
Link to comment
Share on other sites

[!--quoteo(post=377856:date=May 28 2006, 10:56 AM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 10:56 AM) [snapback]377856[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Ugh so frustrating! I added a } after the header part but now I get this:

[a href=\"http://www.thecodingplace.com/dl/usersystem/register.php\" target=\"_blank\"]http://www.thecodingplace.com/dl/usersystem/register.php[/a]
[/quote]

change in the while statement array to row and then change $username to equal $row[n] replace n with row that username is

row is another way to retreave results for a databse(the one i use) it means instead of putting the row name you want to retrieve you put the number.....
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.