Jump to content

[SOLVED] php / mysql help


hazz995

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/180156-solved-php-mysql-help/
Share on other sites

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.

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.

Archived

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

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