madhuramasamy Posted June 25, 2010 Share Posted June 25, 2010 Iam trying to use temporary tables to store data and make some changes to them. im getting Parse error: parse error, unexpected T_STRING in select statement in the following code. Thanks in advance.. <?php include "basic.php"; include "header.php"; include "dbname.php"; select Chemical_ID, count(Chemical_ID) as stock into #instock from Chem_Inventory where Date_Out='0000-00-00' and (Chemical_ID>=5000 and Chemical_ID<6000); //select Chemical_Name into #instock from Chemicals_waste where instock.chemid=Chemicals_waste.Chemical_ID; $query="select * from #instock order by chemname ASC "; $result=mysql_query($query); print "<h3><p><center>Microlab Chemical Inventory</center></p></h3><br>"; print "<table><tr><td><b>Chemical ID</td><td><b>Chemical Name</td><td><b>In Stock</td></tr>"; while ($sel = mysql_fetch_array($result)){ print "<tr><td>$sel[chemid]</td><td>$sel[chemname]</td><td>$sel[stock]</td></tr>";} print "</table>\n"; drop table #instock; ?> Link to comment https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/ Share on other sites More sharing options...
mrMarcus Posted June 25, 2010 Share Posted June 25, 2010 Did that error come with a line#? Would obviously be helpful to provide that. However, I'm thinking it's #instock in your query, and the missing ; on the last line: drop table will produce one as well. Link to comment https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/#findComment-1077217 Share on other sites More sharing options...
Mchl Posted June 25, 2010 Share Posted June 25, 2010 What is this supposed to be? select Chemical_ID, count(Chemical_ID) as stock into #instock from Chem_Inventory where Date_Out='0000-00-00' and (Chemical_ID>=5000 and Chemical_ID<6000); //select Chemical_Name into #instock from Chemicals_waste where instock.chemid=Chemicals_waste.Chemical_ID; You can't have SQL mixed with your PHP. And I don't think using # in table names is such a good idea.... Link to comment https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/#findComment-1077220 Share on other sites More sharing options...
madhuramasamy Posted June 25, 2010 Author Share Posted June 25, 2010 The error was on line 4 <?php include "basic.php"; include "header.php"; include "dbname.php"; dbconnect("MICROLAB","MICROLAB","Charles1","web6.duc.auburn.edu"); select Chemical_ID, count(Chemical_ID) as stock into #instock from Chem_Inventory where Date_Out='0000-00-00' and (Chemical_ID>=5000 and Chemical_ID<6000); $query="select * from #instock order by chemname ASC "; $result=mysql_query($query); print "<h3><p><center>Microlab Chemical Inventory</center></p></h3><br>"; print "<table><tr><td><b>Chemical ID</td><td><b>Chemical Name</td><td><b>In Stock</td></tr>"; while ($sel = mysql_fetch_array($result)){ print "<tr><td>$sel[chemid]</td><td>$sel[chemname]</td><td>$sel[stock]</td></tr>";} print "</table>\n"; drop table #instock; ?> Link to comment https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/#findComment-1077227 Share on other sites More sharing options...
mrMarcus Posted June 25, 2010 Share Posted June 25, 2010 # works as a commenting syntax in PHP. you actually commented out half your query resulting in the parse error. Same is happening with your last line. Link to comment https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/#findComment-1077230 Share on other sites More sharing options...
Mchl Posted June 25, 2010 Share Posted June 25, 2010 Besides the fact, that PHP has no idea what 'select' or 'drop' is. And how are you actually benefiting from using this temporary table is beyond me... Not to mention you don't seem to be creating it anywhere. Link to comment https://forums.phpfreaks.com/topic/205857-temporary-tables-in-sql/#findComment-1077231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.