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

Link to comment
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.

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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