I need some mysql direction.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
polishvalor
Forum Newbie
Posts: 13
Joined: Sat Nov 06, 2010 10:45 pm

I need some mysql direction.

Post 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.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: I need some mysql direction.

Post by Neilos »

http://www.w3schools.com/php/php_mysql_intro.asp

Has mysql tutorials that are easy to follow.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: I need some mysql direction.

Post 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'
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
polishvalor
Forum Newbie
Posts: 13
Joined: Sat Nov 06, 2010 10:45 pm

Re: I need some mysql direction.

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: I need some mysql direction.

Post 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?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
polishvalor
Forum Newbie
Posts: 13
Joined: Sat Nov 06, 2010 10:45 pm

Re: I need some mysql direction.

Post 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 ?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: I need some mysql direction.

Post 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.
polishvalor
Forum Newbie
Posts: 13
Joined: Sat Nov 06, 2010 10:45 pm

Re: I need some mysql direction.

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