Page 1 of 1

I need some mysql direction.

Posted: Thu Jan 06, 2011 9:24 pm
by polishvalor
Could anyone direct me towards a good guide or book which can explain to me how tables in mysql databases work and are to be set up. I am trying to set up a site where i need input into several tables on the same database at once, which does not work for me. I've skimmed about a little and saw I should refrence the tables to one main table via an index key or something of the like or other. I need to find a place where I can just review how I can link several tables together.
OR
If you could help me figure out why something like this:

Code: Select all

$newuser = mysql_query("INSERT INTO members (username, password, userlevel, email) VALUES ('$username', '$password', '$userlevel', '$email')");
$newinfo = mysql_query("INSERT INTO members_info SET username='$username', userlevel='$userlevel', email='$email', join date='$joindate' ");
does not work. The second table has a bunch of more variables such as first name, last name, dob, location, profile pic, registration code, join date. when i omit a field for the first one it works fine, the second one won't work at all. I used 'SET' in the second one because i thought maybe it would not require all fields.

Re: I need some mysql direction.

Posted: Thu Jan 06, 2011 10:43 pm
by Neilos
http://www.w3schools.com/php/php_mysql_intro.asp

Has mysql tutorials that are easy to follow.

Re: I need some mysql direction.

Posted: Fri Jan 07, 2011 12:51 am
by social_experiment
Use the same format as the first query for the second query. SET is only used with UPDATE in SQL queries i.e UPDATE table SET field = 'value'

Re: I need some mysql direction.

Posted: Fri Jan 07, 2011 10:56 am
by polishvalor
Neilos wrote:
//www.w3schools.com/php/php_mysql_intro.asp[/url]

Has mysql tutorials that are easy to follow.[/quote]
That does not apply to the question im posing. Thanks anyway.
social_experiment wrote:Use the same format as the first query for the second query. SET is only used with UPDATE in SQL queries i.e UPDATE table SET field = 'value'
I used it before i used 'set' still did not work.

Re: I need some mysql direction.

Posted: Fri Jan 07, 2011 11:10 am
by social_experiment
polishvalor wrote:I used it before i used 'set' still did not work.
What happens if you change the second query to look like the first one?

Re: I need some mysql direction.

Posted: Fri Jan 07, 2011 12:51 pm
by polishvalor
i worked backwards and removed the variables and also included die(mysql_error()) and apparently 'join date' must be 'joindate' . so now my question is...why can't there be a space in the column name or should i rather write join_date ?

Re: I need some mysql direction.

Posted: Fri Jan 07, 2011 1:40 pm
by mikosiko
This was your first question:
polishvalor wrote:Could anyone direct me towards a good guide or book which can explain to me how tables in mysql databases work and are to be set up
and another member of the forum gave you this:
http://www.w3schools.com/php/php_mysql_intro.asp

Has mysql tutorials that are easy to follow.
your answer:
That does not apply to the question im posing
well... yes it apply completely... matter of fact in Chapter 3 of that tutorial are clearly posted examples of how the INSERT clause works
http://www.w3schools.com/php/php_mysql_insert.asp

maybe you didn't assign the time to read what was provide to you

answering you last question:
why can't there be a space in the column name or should i rather write join_date ?
In general is not good idea and good practice to name columns using spaces, even when is allowed in MYSQL; problems arise when you try to use them, in those cases you must enclose the field name in backticks
like `join date` a better option is rename the field.

Re: I need some mysql direction.

Posted: Fri Jan 07, 2011 2:08 pm
by polishvalor
mikosiko wrote:well... yes it apply completely... matter of fact in Chapter 3 of that tutorial are clearly posted examples of how the INSERT clause works
http://www.w3schools.com/php/php_mysql_insert.asp

maybe you didn't assign the time to read what was provide to you
you are quite right, i was busy thinking about how to link multiple tables together i didn't realize the function to insert would be the same either way.