Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427548
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427553
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427554
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427561
Share on other sites

*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>
<? } ?>

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427583
Share on other sites

<?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>
<? } ?>

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427597
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427624
Share on other sites

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>
<? } ?>

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427627
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427641
Share on other sites

sorry wrong logic  :D

<?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>
<? } ?>

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427652
Share on other sites

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());

Link to comment
https://forums.phpfreaks.com/topic/84018-solved-error-message/#findComment-427659
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.