hazz995 Posted November 3, 2009 Share Posted November 3, 2009 Is this the right place for this? (Sorry I'm new here) Anyways, I'm having trouble with: $query = "SELECT name, comment FROM hcdb"; Is it possible to add another field 'score' to that so that it returns comment from hcdb and score from hcdb? Rest of the code for this part: $res = mysql_query($query) while ($user = mysql_fetch_assoc($res)) { does loop stuff like showing a table with name, scores and comment. } Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 3, 2009 Share Posted November 3, 2009 If there is a column named 'score' in 'hcdb' table, then yes. Just add a comma after 'comment' and type in 'score' $query = "SELECT name, comment, score FROM hcdb"; Quote Link to comment Share on other sites More sharing options...
hazz995 Posted November 5, 2009 Author Share Posted November 5, 2009 Alright thanks that part works now. Although now I am having trouble with a query: $query = "INSERT INTO hi VALUES('".$_GET["name"].",".$_GET["score"].",".$_GET["user_comment"]."')"; I get this error: Couldn't execute INSERT INTO hi VALUES('test name,15,test comment'): Column count doesn't match value count at row 1 I know for a matter of fact that they are all and the only Column's in the database since I have tested it using another simpler query which worked past this point. Quote Link to comment Share on other sites More sharing options...
waynewex Posted November 5, 2009 Share Posted November 5, 2009 Alright thanks that part works now. Although now I am having trouble with a query: $query = "INSERT INTO hi VALUES('".$_GET["name"].",".$_GET["score"].",".$_GET["user_comment"]."')"; I get this error: Couldn't execute INSERT INTO hi VALUES('test name,15,test comment'): Column count doesn't match value count at row 1 I know for a matter of fact that they are all and the only Column's in the database since I have tested it using another simpler query which worked past this point. It means that your table has a certain number of columns and that you must insert the same number of values. The problem is mainly with your query. You shouldn't be making queries like that, you should really be making them like this: $query = "INSERT INTO table_name (col_name_1,col_name_2,col_name_3) VALUES('$val_for_1','$val_for_2','$val_for_3')"; The problem with your style of query is that a) you have to insert a value into every column and b) that if you add a column to your table at a later date, all previous queries will need to be changed. Quote Link to comment Share on other sites More sharing options...
hazz995 Posted November 5, 2009 Author Share Posted November 5, 2009 Okay thanks its working now had to remove the double quotes from the [ ] as well 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.