judacoor Posted July 20, 2007 Share Posted July 20, 2007 Look, i'm getting this error message after performing a query with php:Error: Column count doesn't match value count at row 1and i have no idea what it is......Please help me! i'm stuck!! Link to comment Share on other sites More sharing options...
vijay Posted July 21, 2007 Share Posted July 21, 2007 Hi.. May I have your 'query' and 'table structure'?Regards,Vijay Link to comment Share on other sites More sharing options...
Synook Posted July 22, 2007 Share Posted July 22, 2007 Are you trying to perform an INSERT query? If so, then that means that the number of columns you have specified for insertion is not the same as the count of the list of values you gave.For example, if I tried to perform the query INSERT INTO table (name, email) VALUES ('John'); then the error would be returned because the number of columns specified for insertion (2) is not the same as the number of values given (1).Hope that helped Link to comment Share on other sites More sharing options...
judacoor Posted July 23, 2007 Author Share Posted July 23, 2007 Uhmmmm right!And I certainly am missing one field.....the first one, wich is 'id_user' but I used the "auto-increment" option, so I thought I didn't have to specify a value for mysql would automatically generate it....So what should I do? Link to comment Share on other sites More sharing options...
aspnetguy Posted July 23, 2007 Share Posted July 23, 2007 put in an empty string for the auto_increment column VALUES ('','John') Link to comment Share on other sites More sharing options...
judacoor Posted July 23, 2007 Author Share Posted July 23, 2007 Thanks!it's working now!!!thanks a lot!!! Link to comment Share on other sites More sharing options...
aspnetguy Posted July 23, 2007 Share Posted July 23, 2007 no problem Link to comment Share on other sites More sharing options...
Synook Posted July 25, 2007 Share Posted July 25, 2007 You could also, if you wanted to, only specify certain columns. So, if you had your `users` table +--------+----------+---------+|user_id |user_name |user_age |+--------+----------+---------+ and only wanted to insert the user's name you could do INSERT INTO users (user_name) VALUES ('John') Link to comment Share on other sites More sharing options...
judacoor Posted July 31, 2007 Author Share Posted July 31, 2007 Hey guys.....Now I'm getting the following error:Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program......and I haven't been able to figure out what it is.....Here's the function that's causing the error:function getConsult(){$id_user = $_SESSION['id_user];$result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user",$link) or die(mysql_error());return $result;}Since the error mentions something about a not-valid Link resource........I thought it could probably be the $link variable, which is:function getLink(){$link=mysql_connect("localhost","root","");$selectdb=mysql_select_db("mydb",$link);if($link==false){echo "Error connecting to DB";exit();}else if($selectdb==false){echo "Error selecting DB";exit();}else{return $link;}}but this $link variable works perfectly in the other querys I've made....so I don't know what the ###### is going on...Every functions is in a diferent file, actually in a different folder.........but I used the "include (file.php)" in every case so...........really.............I need some help!!!!Please help me out!!!! Link to comment Share on other sites More sharing options...
justsomeguy Posted July 31, 2007 Share Posted July 31, 2007 You need to specify global variables in functions in order to use the global version of the variable. Otherwise it is trying to use a variable called $link that was defined in the function, and obviously there is no $link variable defined in the function. Add this line at the top of the function:global $link; Link to comment Share on other sites More sharing options...
smartalco Posted August 1, 2007 Share Posted August 1, 2007 $result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user",$link) or die(mysql_error());you have an open apostrophe, change it to this$result = mysql_query("SELECT * FROM `consult` WHERE `id_user` = '$id_user'",$link) or die(mysql_error()); Link to comment Share on other sites More sharing options...
judacoor Posted August 2, 2007 Author Share Posted August 2, 2007 Oh....but the $link variable is defined above the function.........like this:<?php$link=Conn();function getConsult(){$id_user = $_SESSION['id_user];$result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user",$link) or die(mysql_error());return $result;}?>And the thing is that $link works perfectly with another function that i've been using it with.........I changed it anyways.......alas it still doesn't work:<?phpglobal $link;$link=Conn();function getConsult(){$id_user = $_SESSION['id_user];$result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user",$link) or die(mysql_error());return $result;}?>Any ideas??Please! Link to comment Share on other sites More sharing options...
Synook Posted August 2, 2007 Share Posted August 2, 2007 No, the problem is in this line: $result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user",$link) or die(mysql_error()); See this: $result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user",$link) or die(mysql_error()); ?There is no closing apostrophe for the id_user value. It needs to be like this: $result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user'",$link) or die(mysql_error());See, or else you open the value for id_user but never close it Link to comment Share on other sites More sharing options...
smartalco Posted August 2, 2007 Share Posted August 2, 2007 thanks for reading my post judacoor /sarcasm (if you don't know what im talking about, look at post 11 in this thread, or the post right above this (Synooks)) Link to comment Share on other sites More sharing options...
justsomeguy Posted August 2, 2007 Share Posted August 2, 2007 Instead of this: <?phpglobal $link;$link=Conn();function getConsult(){ I meant for you to do this: <?php$link=Conn();function getConsult(){ global $link; Link to comment Share on other sites More sharing options...
judacoor Posted August 3, 2007 Author Share Posted August 3, 2007 smartalco and synook: I'm terrybly sorry....I forgot to mention earlier that it was actually a copy-paste mistake........the code is as follows:$result = mysql_query("SELECT * FROM `consult` WHERE `consult`.`id_user` = '$id_user'",$link) or die(mysql_error());so I don't see any errors at first sight, but I forgot to to tell you guys in the last post, for I was in a hurry when I posted it.I'd appreciate any further help!!! Link to comment Share on other sites More sharing options...
judacoor Posted August 6, 2007 Author Share Posted August 6, 2007 I'll try using the global attribute like you say Justsomeguy, and I will tell you guys later what happened Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.