Jump to content

What does this error message mean?


judacoor

Recommended Posts

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

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

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

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

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

$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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...