php? Posted January 1, 2008 Share Posted January 1, 2008 I get this error message from the code below: Column count doesn't match value count at row 1 I have 3 columns... username, password, and email Any suggestions? <?php require_once('db.php'); include('functions.php'); if(isset($_POST['register'])) { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { $query = mysql_query("INSERT INTO pending (`Username` , `Password`, `Email`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 1, 2008 Share Posted January 1, 2008 You are wanting to insert into 3 fields, but you are giving 4 values. Your fourth value is random_string('alnum', 32) Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Okay now i get this =D You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''email@email.com' at line 1 Code that might be effecting it: $query = mysql_query("INSERT INTO pending (`Username` , `Password`, `Email`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 you for got the '" '".mysql_real_escape_string($_POST['email'])."' ant tips process your data before going to query eg.. $mail = mysql_real_escape_string($_POST['email']); so you will be then using $mail i n your query in that case it abit clearer Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted January 1, 2008 Share Posted January 1, 2008 try $query = mysql_query("INSERT INTO pending (`Username` , `Password`, `Email`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 try $query = mysql_query("INSERT INTO pending (`Username` , `Password`, `Email`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."')") or die(mysql_error()); $email = mysql_real_escape_string($_POST['email']); $uname = mysql_real_escape_string($_POST['username']); $pword = mysql_real_escape_string(md5($_POST['password'])); $query = mysql_query("INSERT INTO pending (`Username`,`Password`,`Email`) VALUES ('".$uname."','".$pword."','".$email."')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 *sigh* now i get this from tengs solution You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM pending WHERE Username = 'MEME'' at line 1 But it still sends it to the database. <?php require_once('db.php'); include('functions.php'); if(isset($_POST['register'])) { if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { $email = mysql_real_escape_string($_POST['email']); $uname = mysql_real_escape_string($_POST['username']); $pword = mysql_real_escape_string(md5($_POST['password'])); $query = mysql_query("INSERT INTO pending (`Username`,`Password`,`Email`) VALUES ('".$uname."','".$pword."','".$email."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 <?php require_once('db.php'); include('functions.php'); function checkempty($var){// check works if all your field is required returns aray containing the empty fields $empty = array(); // it may not waht actually you need but you may edit it better than haviing tons of paarametr in your ifs foreach($var as $value){ if(empty($value)){ $empty[] = $value; } } return $empty; } if(isset($_POST['register'])) { if(count(checkempty($_POST)) > 0) { $email = mysql_real_escape_string($_POST['email']); $uname = mysql_real_escape_string($_POST['username']); $pword = mysql_real_escape_string(md5($_POST['password'])); $query = mysql_query("INSERT INTO pending (`Username`,`Password`,`Email`) VALUES ('".$uname."','".$pword."','".$email."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Now when i try registering it comes up with every time ^.^ There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match Quote Link to comment Share on other sites More sharing options...
revraz Posted January 1, 2008 Share Posted January 1, 2008 Need to remove the last comma here $getUser = mysql_query("SELECT ID, Username, Email, FROM, <--- Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Theres no comma there... Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Something in tangs code is making the error message pop up and nothing else happening Quote Link to comment Share on other sites More sharing options...
revraz Posted January 1, 2008 Share Posted January 1, 2008 It's right there unless you already removed it $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); Theres no comma there... Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 This does the error... there never was a comma where you said. <?php require_once('db.php'); include('functions.php'); function checkempty($var){// check works if all your field is required returns aray containing the empty fields $empty = array(); // it may not waht actually you need but you may edit it better than haviing tons of paarametr in your ifs foreach($var as $value){ if(empty($value)){ $empty[] = $value; } } return $empty; } if(isset($_POST['register'])) { if(count(checkempty($_POST)) > 0) { $email = mysql_real_escape_string($_POST['email']); $uname = mysql_real_escape_string($_POST['username']); $pword = mysql_real_escape_string(md5($_POST['password'])); $query = mysql_query("INSERT INTO pending (`Username`,`Password`,`Email`) VALUES ('".$uname."','".$pword."','".$email."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) {//there's only one MATRIX :PP $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 <?php require_once('db.php'); include('functions.php'); function checkempty($var){// check works if all your field is required returns aray containing the empty fields $empty = array(); // it may not waht actually you need but you may edit it better than haviing tons of paarametr in your ifs foreach($var as $value){ if(empty($value)){ $empty[] = $value; } } return $empty; } if(isset($_POST['register'])){ if(count(checkempty($_POST)) > 0) { $email = mysql_real_escape_string($_POST['email']); $uname = mysql_real_escape_string($_POST['username']); $pword = mysql_real_escape_string(md5($_POST['password'])); $query = mysql_query("INSERT INTO pending (`Username`,`Password`,`Email`) VALUES ('".$uname."','".$pword."','".$email."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".$uname."'") or die(mysql_error()); if(mysql_num_rows($getUser)>0){//there's only one MATRIX :PP $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { print_r(checkempty($_POST)); $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> try and tell us what happen Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 It sends to database.. but still comes up with this error: Array ( ) There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 sorry wrong logic <?php require_once('db.php'); include('functions.php'); function checkempty($var){// check works if all your field is required returns aray containing the empty fields $empty = array(); // it may not waht actually you need but you may edit it better than haviing tons of paarametr in your ifs foreach($var as $value){ if(empty($value)){ $empty[] = $value; } } return $empty; } if(isset($_POST['register'])){ if(count(checkempty($_POST)) <= 0) { $email = mysql_real_escape_string($_POST['email']); $uname = mysql_real_escape_string($_POST['username']); $pword = mysql_real_escape_string(md5($_POST['password'])); $query = mysql_query("INSERT INTO pending (`Username`,`Password`,`Email`) VALUES ('".$uname."','".$pword."','".$email."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".$uname."'") or die(mysql_error()); if(mysql_num_rows($getUser)>0){//there's only one MATRIX :PP $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { print_r(checkempty($_POST)); $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br /> Password: <input type="password" id="password" name="password" size="32" value="" /><br /> Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br /> Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br /> <input type="submit" name="register" value="register" /><br /> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 you should be fine now and note you put some condition inside if(count(checkempty($_POST)) <= 0) { eg matching of mails etc.. Quote Link to comment Share on other sites More sharing options...
php? Posted January 1, 2008 Author Share Posted January 1, 2008 Now this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM pending WHERE Username = 'Test2'' at line 1 Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 1, 2008 Share Posted January 1, 2008 see this line $getUser = mysql_query("SELECT ID, Username, Email, FROM pending WHERE Username = '".$uname."'") or die(mysql_error()); that is what the other gus is telling you should have edit that sorry the comma after email $getUser = mysql_query("SELECT ID, Username, Email FROM pending WHERE Username = '".$uname."'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Ooh there we go.... the other "gus" put a comma after FROM Quote Link to comment Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 guess time to mark this as solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.