/    Sign up×
Community /Pin to ProfileBookmark

Registration Page Error

I am trying to Create registration form for an application i am making i have a drop down list menu and when i select somthing on that list say Sales

i have in the top part of my code this

[CODE]
$username=trim($_POST[‘username’]);
$password=trim($_POST[‘password’]);
$email=trim($_POST[’email’]);
$race=$_POST[‘race’];
[/CODE]

and the other part of the code my query part

[CODE]
the query i have is
$iQuery=”INSERT INTO members values(”,’$username’,’$spass’,’$email’,’$race’);
[/CODE]

And it is saying Error:Colume Count doesnt match value at row 1

How can i fix this?

to post a comment
PHP

19 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJul 18.2006 — I think your query isnt right.

some thing like this maybe?

[code=php]
$sql="INSERT INTO table(field,field,field,field)
VALUES('$field','$field','$field','$field')";

mysql_query($sql) or die ("Error in the query:". mysql_error());[/code]


both valuse should go in the same order as they are in the table structure
Copy linkTweet thisAlerts:
@SeanieCJul 18.2006 — Yeah you have to specify the columns you would like the data to go into.
Copy linkTweet thisAlerts:
@william232authorJul 18.2006 — $iQuery="INSERT INTO members VALUES('','$username','$spass','$email','$race')";

but i have mid which is set to INT and that is Member ID
Copy linkTweet thisAlerts:
@SheldonJul 18.2006 — read the two replies and think, We have told you the problem.

You need to specify the fields
Copy linkTweet thisAlerts:
@SeanieCJul 18.2006 — Okay, first off you should really use the sprintf() function to put variables in a query string. so..

[CODE]$iQuery=sprintf("INSERT INTO members(username, password, email, race) VALUES (%s, %s, %s, %s)", $username, $spass, $email, $race);[/CODE]

This should not affect your memberID column unless you didn't set it to auto_increase in which case I suggest you do ? . Give it a go and if you don't understand it message back and I'll try to explain a bit better.

Hope it helps!
Copy linkTweet thisAlerts:
@aussie_girlJul 18.2006 — $iQuery="INSERT INTO members VALUES('','$username','$spass','$email','$race')";

but i have mid which is set to INT and that is Member ID[/QUOTE]


Hello, if your member ID is set to auto_encrement you need to use NULL not an empty string
<i>
</i>$iQuery="INSERT INTO members VALUES(NULL,'$username','$spass','$email','$race')";
Copy linkTweet thisAlerts:
@SeanieCJul 18.2006 — Ahh not forgetting the columns,

[code=php]$iQuery=sprintf("INSERT INTO members(memberID, username, password, email, race) VALUES (NULL, %s, %s, %s, %s)", $username, $spass, $email, $race);[/code]

There, that should work perfect now, thanks Aussie that cleared up a query I had too. ?
Copy linkTweet thisAlerts:
@aussie_girlJul 18.2006 — Ahh not forgetting the columns,

[code=php]$iQuery=sprintf("INSERT INTO members(memberID, username, password, email, race) VALUES (NULL, %s, %s, %s, %s)", $username, $spass, $email, $race);[/code]

There, that should work perfect now, thanks Aussie that cleared up a query I had too. ?[/QUOTE]

I don't believe that will work, what is %s,...and you don't need to include the columns unless there were more columns in the table that wasn't included then you would have to...the original poster had it nearly right the first time.. all he had to do was change the empty string to NULL and it should have worked
Copy linkTweet thisAlerts:
@SeanieCJul 18.2006 — %s is '%s' perhaps? or a representation of a respective variable. It's used in the sprintf() function is it not?

I didn't know that about columns either. Thank you. ?
Copy linkTweet thisAlerts:
@william232authorJul 18.2006 — now it is giving me Error: Unkown Column '$username in field list' but i just copied what the sql you gave me above and it gave me this error.
Copy linkTweet thisAlerts:
@SeanieCJul 18.2006 — Oh, thats probably because the column you have in your database is different. Check which column stores the usernames and change the script appropriately.
Copy linkTweet thisAlerts:
@bokehJul 18.2006 — Yeah you have to specify the columns you would like the data to go into.[/QUOTE]That's not true. Specifying the columns is optional. But it is handy to specify them as it allows you to choose the order and to insert subsets.
Copy linkTweet thisAlerts:
@SeanieCJul 18.2006 — Yeah that has already been corrected, thanks though Bokeh. ?

Even though I know little, i'd still rather give some input, because then when I am corrected, I learn a bigger lesson then the person who had no idea. ?
Copy linkTweet thisAlerts:
@william232authorJul 18.2006 — How can i go about fixing this?
Copy linkTweet thisAlerts:
@aussie_girlJul 19.2006 — How can i go about fixing this?[/QUOTE]
Use your first original query and put NULL as your first value not the empty string quotes. We seem to have gone all over the place with this topic
Copy linkTweet thisAlerts:
@aussie_girlJul 19.2006 — %s is '%s' perhaps? or a representation of a respective variable. It's used in the sprintf() function is it not?

I didn't know that about columns either. Thank you. ?[/QUOTE]


PHP varaibles are prefixed with $ signs not % and I have never used the sprintf() function, it seems people with Perl or C programming backgrounds use it
Copy linkTweet thisAlerts:
@william232authorJul 19.2006 — i have fixed it now thanks all for your help and taking part to help me ?
Copy linkTweet thisAlerts:
@SeanieCJul 19.2006 — [code=php]
$iQuery="INSERT INTO members values('$username','$spass','$email','$race');
[/code]


Try that.

Sorry didn't see that it had been fixed.
Copy linkTweet thisAlerts:
@SeanieCJul 19.2006 — PHP varaibles are prefixed with $ signs not % and I have never used the sprintf() function, it seems people with Perl or C programming backgrounds use it[/QUOTE]

Hmm, I use it in PHP to declare my variables in my query string.

$variable1 = 8;

$variable2 = 43;

sprintf("SELECT * FROM table WHERE column1='%s' AND column2='%s'", $variable1, $variable2);

Would check column1 for 8 and column2 for 43 and the results would be the entire row of the matching fields. ?
×

Success!

Help @william232 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...