Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 02-17-2005, 02:04 AM   #1 (permalink)
Ste_Boro
Registered User
 
Join Date: Feb 2005
Posts: 1
Ste_Boro is on a distinguished road
Inserting the results of a select query into seperate tables

I'm building a music website using php/mysql for my final year project at university. I'm trying to do a select query on the band_id and then insert the result into 2 more tables that have the band id as a foreign key.

$result="select (`band_id`) from band
where band_name = '$band_name'";
mysql_query($result, $dbh);

//$band_name is the value entered into the edit box on my form and seen as the query returns $result I was thinking I could just slot it into the other queries and it would work like so:

$sql="INSERT INTO `member` (`band_id`)
VALUES($result)";
mysql_query($sql, $dbh);

$sql="INSERT INTO `user` (`band_id`)
VALUES($result)";
mysql_query($sql, $dbh);

Obviousley it doesn't work.

Any help would be appreciated.
Ste_Boro is offline   Reply With Quote
Old 02-17-2005, 05:05 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
It seems like your SQL statements need to include more information about the record being inserted. (eg: name/id/etc..). Not knowing the structure of the member and user tables, I can't be certain.

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 11:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting