june_c21 Posted October 20, 2007 Share Posted October 20, 2007 $month = $_POST ['month']; $gf = $_POST ['gf']; $equipment = $_Get ['equipment']; $query= "INSERT INTO report( month,gf,equipment) VALUES ('$month','1','$equipment') "; $result = mysql_query($query,$dblink); my problem is the month & gf are insert by users to report table but equipment is taken from different table and want to insert into report table. how to write the code? thanks Quote Link to comment https://forums.phpfreaks.com/topic/74090-table-helps/ Share on other sites More sharing options...
Simon Moon Posted October 20, 2007 Share Posted October 20, 2007 Query the other table and put the result you need from there into a variable first. Quote Link to comment https://forums.phpfreaks.com/topic/74090-table-helps/#findComment-374143 Share on other sites More sharing options...
Barand Posted October 20, 2007 Share Posted October 20, 2007 or you could $query= "INSERT INTO report( month,gf,equipment) SELECT '$month', '1', equipment FROM othertable WHERE whatever"; Quote Link to comment https://forums.phpfreaks.com/topic/74090-table-helps/#findComment-374250 Share on other sites More sharing options...
june_c21 Posted October 21, 2007 Author Share Posted October 21, 2007 SQL query: SELECT equipment FROM equipment WHERE equipment = $_GET[ 'equipment'] INSERT INTO report( MONTH , gf, equipment, viscosity, water, tan, oil, wear, remarks ) VALUES ( '$month', '1', '$equipment', '$viscosity', '$water', '$tan', '$oil', '$wear', '$remarks' ) LIMIT 0 , 30 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[ 'equipment' ] INSERT INTO report ( month , gf , equipment , viscosity , water' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/74090-table-helps/#findComment-374654 Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 We know that month and gf come from user input. SELECT equipment FROM equipment WHERE equipment = $_GET[ 'equipment'] Why GET when other data is POST? If $_GET['equipment'] contains "widget" then all that does is return "widget" - waste of time. Where do these come from - '$viscosity', '$water', '$tan', '$oil', '$wear', '$remarks' ? What does the equipment table look like? Is the value for equipment same in every record in report table or do you need to select various valeues of equipment from the equipment table - if so what are the selection criteria? Quote Link to comment https://forums.phpfreaks.com/topic/74090-table-helps/#findComment-374668 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.