devhooda Posted September 8, 2005 Posted September 8, 2005 createand insert doew not work from a php file but works when i execute the txt file on mysql prompt.create and insert works from commandline of mysqlfrom PHP sctipt I am trying to enter values into a web form and submit the values to the table in database.after hitting submit I get this errorError! Could not insert values: Query was emptypls help me hereregardsDavender
devhooda Posted September 9, 2005 Author Posted September 9, 2005 (edited) On entering data in the form when we press submit it returns Error! Could not insert values: Query was empty and the same type of script is working with another table with just five fields It is wierd I wasted three days on it SO please look at the code and suggest the problem. Lots of thanks for help !!!! <html> <head> </head> <body> <? //initilize PHP if($_POST['submit']) //If submit is hit { $connect = mysql_pconnect(localhost, hoodad, mysql); mysql_select_db("test"); /*drop table if exists sitelocation; $result=create table sitelocation(SiteLabel varchar(3) UNIQUE, SiteDate date, Watershed varchar(25), SubBasin varchar(25), Country varchar(25), DigitHydrologicUnitCode_6 varchar(6), DigitHydrologicUnitCode_8 varchar(8), DigitHydrologicUnitCode_11 varchar(11), GAPSegmentType varchar(15), GAPSegmentLength int, StreamOrder varchar(2), StreamName varchar(30), UTMzone int, UTMeast int, TMnorth int, LegalDescription varchar(25), OmernikEcoregion varchar(5), BaileyEcoregion varchar(7), NearestTown varchar(25), RiverMile int, DrivingDirections varchar(200), PRIMARY KEY(SiteLabel)); if( mysql_query( $result ) ) echo( "Table created successfully." ); else die( "Error! Could not create a table: " . mysql_error() ); */ //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$4 //convert all the posts to variables: $SiteLabel = $_POST['SiteLabel']; $SiteDate = $_POST['SiteDate']; $Watershed = $_POST['Watershed']; $SubBasin = $_POST['SubBasin']; $Country = $_POST['Country']; $DigitHydrologicUnitCode_6 = $_POST['DigitHydrologicUnitCode_6']; $DigitHydrologicUnitCode_8 = $_POST['DigitHydrologicUnitCode_8']; $DigitHydrologicUnitCode_11 = $_POST['DigitHydrologicUnitCode_11']; $GAPSegmentType = $_POST['GAPSegmentType']; $GAPSegmentLength = $_POST'GAPSegmentLength']; $StreamOrder = $_POST['StreamOrder']; $StreamName = $_POST['StreamName']; $UTMzone = $_POST['UTMzone']; $UTMeast = $_POST['UTMeast']; $TMnorth = $_POST['TMnorth']; $LegalDescription = $_POST['LegalDescription']; $OmernikEcoregion = $_POST['OmernikEcoregion']; $BaileyEcoregion = $_POST['BaileyEcoregion']; $NearestTown = $_POST['NearestTown']; $riverMile = $_POST['RiverMile']; $DrivingDirections = $_POST['DrivingDirections']; //Insert the values into the correct database with the right fields $result=MYSQL_QUERY("insert into sitelocation (SiteLabel,SiteDate,Watershed,SubBasin,Country, DigitHydrologicUnitCode_6,DigitHydrologicUnitCode_8,DigitHydrologicUnitCode_11,GAPSegmentType, GAPSegmentLength,StreamOrder, StreamName, UTMzone,UTMeast,TMnorth,LegalDescription, OmernikEcoregion,BaileyEcoregion,NearestTown,RiverMile, DrivingDirections) values ('SiteLabel','SiteDate','Watershed','SubBasin','Country', 'DigitHydrologicUnitCode_6','DigitHydrologicUnitCode_8','DigitHydrologicUnitCode_11','GAPSegmentType', 'GAPSegmentLength','StreamOrder', 'StreamName','UTMzone','UTMeast','TMnorth','LegalDescription', 'OmernikEcoregion','BaileyEcoregion','NearestTown','RiverMile','DrivingDirections')"); if( mysql_query( $result ) ) echo( "Values inserted successfully." ); else die( "Error! Could not insert values: " . mysql_error() ); echo "Query Finished<br>"; echo "---------------<br><br>"; echo "CONTENTS of the TABLE LOCATION are : <br>"; $result = mysql_query("select * from sitelocation") or die(mysql_error()); while($r=mysql_fetch_array($result)) { echo "CONTENTS of the TABLE LOCATION are vccvcvc: <br>"; $SiteLabel =$r["SiteLabel"]; $SiteDate =$r["SiteDate"]; $Watershed =$r["Watershed"]; $SubBasin =$r["SubBasin"]; $Country =$r["Country"]; $DigitHydrologicUnitCode_6 =$r["DigitHydrologicUnitCode_6"]; $DigitHydrologicUnitCode_8 =$r["DigitHydrologicUnitCode_8"]; $DigitHydrologicUnitCode_11 =$r["DigitHydrologicUnitCode_11"]; $GAPSegmentType =$r["GAPSegmentType"]; $GAPSegmentLength =$r["GAPSegmentLength"]; $StreamOrder =$r["StreamOrder"]; $StreamName =$rT["StreamName"]; $UTMzone =$r["UTMzone"]; $UTMeast =$r["UTMeast"]; $TMnorth =$r["TMnorth"]; $LegalDescription =$r["LegalDescription"]; $OmernikEcoregion =$r["OmernikEcoregion"]; $BaileyEcoregion =$r["BaileyEcoregion"]; $NearestTown =$r["NearestTown"]; $RiverMile =$r["RiverMile"]; $DrivingDirections =$r["DrivingDirections"]; echo "$SiteLabel $SiteDate $Watershed $SubBasin $Country $DigitHydrologicUnitCode_6<br>"; echo "$DigitHydrologicUnitCode_8 $DigitHydrologicUnitCode_11 $GAPSegmentType<br>"; echo "$GAPSegmentLength $StreamOrder $StreamName $UTMzone $UTMeast<br>"; echo "$TMnorth $LegalDescription $OmernikEcoregion $BaileyEcoregion $NearestTown<br>"; echo "$RiverMile $DrivingDirections<br>"; } } else { // close php so we can put in our code ?> <form method="post" action="insert_location.php"> <TABLE> <TR> <TD>SiteLabel:</TD> <TD><INPUT TYPE='TEXT' NAME='SiteLabel' VALUE='' size=60></TD> </TR> <TR> <TD>SiteDate:</TD> <TD><INPUT TYPE='TEXT' NAME='SiteDate' VALUE='' size=60></TD> </TR><br> <TR> <TD>Watershed:</TD> <TD><INPUT TYPE='TEXT' NAME='Watershed' VALUE='' size=60></TD> </TR> <TR> <TD>SubBasin:</TD> <TD><INPUT TYPE='TEXT' NAME='SubBasin' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>Country:</TD> <TD><INPUT TYPE='TEXT' NAME='Country' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>6DigitHydrologicUnitCode:</TD> <TD><INPUT TYPE='TEXT' NAME='DigitHydrologicUnitCode_6' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>8DigitHydrologicUnitCode:</TD> <TD><INPUT TYPE='TEXT' NAME='DigitHydrologicUnitCode_8' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>11DigitHydrologicUnitCode:</TD> <TD><INPUT TYPE='TEXT' NAME='DigitHydrologicUnitCode_11' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>GAPSegmentType:</TD> <TD><INPUT TYPE='TEXT' NAME='GAPSegmentType' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>GAPSegmentLength:</TD> <TD><INPUT TYPE='TEXT' NAME='GAPSegmentLength' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>StreamOrder:</TD> <TD><INPUT TYPE='TEXT' NAME='StreamOrder' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>StreamName:</TD> <TD><INPUT TYPE='TEXT' NAME='StreamName' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>UTMzone:</TD> <TD><INPUT TYPE='TEXT' NAME='UTMzone' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>UTMeast:</TD> <TD><INPUT TYPE='TEXT' NAME='UTMeast' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>TMnorth:</TD> <TD><INPUT TYPE='TEXT' NAME='TMnorth' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>LegalDescription:</TD> <TD><INPUT TYPE='TEXT' NAME='LegalDescription' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>OmernikEcoregion:</TD> <TD><INPUT TYPE='TEXT' NAME='OmernikEcoregion' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>BaileyEcoregion:</TD> <TD><INPUT TYPE='TEXT' NAME='BaileyEcoregion' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>NearestTown:</TD> <TD><INPUT TYPE='TEXT' NAME='NearestTown' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>RiverMile:</TD> <TD><INPUT TYPE='TEXT' NAME='RiverMile' VALUE='' size=60></TD> </TR> <TR> <TR> <TD>DrivingDirections:</TD> <TD><INPUT TYPE='TEXT' NAME='DrivingDirections' VALUE='' size=60></TD> </TR> <TR> <TR> <TD></TD><br> <TD><INPUT TYPE="submit" name="submit" value="submit"></TD> </TR> </TABLE> </form> <? } //close the else statement ?> </body> </html> &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&77 Structure of the Sitelocation Table is : +----------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------------------+--------------+------+-----+---------+-------+ | SiteLabel | char(3) | | PRI | | | | SiteDate | date | YES | | NULL | | | Watershed | varchar(25) | YES | | NULL | | | SubBasin | varchar(25) | YES | | NULL | | | Country | varchar(25) | YES | | NULL | | | DigitHydrologicUnitCode_6 | varchar(6) | YES | | NULL | | | DigitHydrologicUnitCode_8 | varchar(8) | YES | | NULL | | | DigitHydrologicUnitCode_11 | varchar(11) | YES | | NULL | | | GAPSegmentType | varchar(15) | YES | | NULL | | | GAPSegmentLength | int(11) | YES | | NULL | | | StreamOrder | char(2) | YES | | NULL | | | StreamName | varchar(30) | YES | | NULL | | | UTMzone | int(11) | YES | | NULL | | | UTMeast | int(11) | YES | | NULL | | | TMnorth | int(11) | YES | | NULL | | | LegalDescription | varchar(25) | YES | | NULL | | | OmernikEcoregion | varchar(5) | YES | | NULL | | | BaileyEcoregion | varchar(7) | YES | | NULL | | | NearestTown | varchar(25) | YES | | NULL | | | RiverMile | int(11) | YES | | NULL | | | DrivingDirections | varchar(200) | YES | | NULL | | +----------------------------+--------------+------+-----+---------+-------+ 21 rows in set (0.00 sec) Edited September 9, 2005 by prathapml
dman Posted September 9, 2005 Posted September 9, 2005 (edited) First, please use code tags. (or quote tags if code tags alter the code, like they did when I tried them here)At a glance it looks like this string is wrong.$result=MYSQL_QUERY("insert into sitelocation (SiteLabel,SiteDate,Watershed,SubBasin,Country,DigitHydrologicUnitCode_6,DigitHydrologicUnitCode_8,DigitHydrologicUnitCode_11,GAPSegmentType,GAPSegmentLength,StreamOrder, StreamName, UTMzone,UTMeast,TMnorth,LegalDescription,OmernikEcoregion,BaileyEcoregion,NearestTown,RiverMile, DrivingDirections)values('SiteLabel','SiteDate','Watershed','SubBasin','Country','DigitHydrologicUnitCode_6','DigitHydrologicUnitCode_8','DigitHydrologicUnitCode_11','GAPSegmentType','GAPSegmentLength','StreamOrder', 'StreamName','UTMzone','UTMeast','TMnorth','LegalDescription','OmernikEcoregion','BaileyEcoregion','NearestTown','RiverMile','DrivingDirections')");if( mysql_query( $result ) )you are including "mysql_query" in the actual query string.try it like$result="insert into sitelocation (SiteLabel,SiteDate,Watershed,SubBasin,Country,DigitHydrologicUnitCode_6,DigitHydrologicUnitCode_8,DigitHydrologicUnitCode_11,GAPSegmentType,GAPSegmentLength,StreamOrder, StreamName, UTMzone,UTMeast,TMnorth,LegalDescription,OmernikEcoregion,BaileyEcoregion,NearestTown,RiverMile, DrivingDirections)values('SiteLabel','SiteDate','Watershed','SubBasin','Country','DigitHydrologicUnitCode_6','DigitHydrologicUnitCode_8','DigitHydrologicUnitCode_11','GAPSegmentType','GAPSegmentLength','StreamOrder', 'StreamName','UTMzone','UTMeast','TMnorth','LegalDescription','OmernikEcoregion','BaileyEcoregion','NearestTown','RiverMile','DrivingDirections')";if( mysql_query( $result ) ) Edited September 9, 2005 by dman
devhooda Posted September 9, 2005 Author Posted September 9, 2005 Thanks Dmon that works thanks a lotI have nother problem:when I echo " .......contents of the 21 fields in DB......" and display in the browser the rows of the tables are wrapped (means one row is bigger than the desktop screen size there for one row breaks and half part of one low is displayed in the second line), is there any way I can display it as a single line as scroling on the side bar of the browser , it looks like this :but i want all of line 1 in a single line and line no. 2 in second line :1 0000-00-00 Missouri Bad Jackson 3.3113E+113208 4 S Fork Bad River 14 2726654866378 T1S R19E SEC 34 43F 331Fs Cottonwood96 "I-90 exit 143. S on 732 0000-00-00 Missouri Bad Jackson 3.3113E+113304 5 S Fork Bad River 14 2772304869889 T1S R20E SEC 19 43F 331Fs Cottonwood90 "From Cottonwoodplease suggest some thingthanks a lot gor great help.
dman Posted September 9, 2005 Posted September 9, 2005 try replacing the blank spaces in your output string with non-breaking spaces ( ) That will stop it from wrapping.1 0000-00-00 Missouri Bad Jackson 3.3113E+.... etc.
devhooda Posted September 9, 2005 Author Posted September 9, 2005 Yes that is right but reduces multiple white spaces to single white spacesIn my case I have a very big text in one line so it does not fit in one line and goes to second line (I want to display it if we can see the side scrolling)http://coers6000.sdstate.edu/~hoodad/Sitel..._updated_DB.phpMy script is on this link you can see there what is the probelmI want to keep one row of the database in one line only, where part of the fields are visible on the screenI want to use the scroll bar at the bottom to see the part of the fields hiddenThanks for your helpI tried to explain but u mayhave questions about what I need.
dman Posted September 9, 2005 Posted September 9, 2005 but reduces multiple white spaces to single white spaces no, use one for each space you want to insert. The browser is wrapping on the blank space, if you replace them all with it won't wrap and will display horiz. scrollbar.
devhooda Posted September 12, 2005 Author Posted September 12, 2005 Thanks a lot and very sorry for the inconvenience as I am sort of new to this.this is the echo CODE+++++++++++++++++++++++++++echo "$SiteLabel $SiteDate $Watershed $SubBasin $Country $DigitHydrologicUnitCode_6 "; echo " $DigitHydrologicUnitCode_8 $DigitHydrologicUnitCode_11 $GAPSegmentType "; echo " $GAPSegmentLength $StreamOrder $StreamName $UTMzone $UTMeast "; echo " $TMnorth $LegalDescription $OmernikEcoregion $BaileyEcoregion $NearestTown "; echo " $RiverMile $DrivingDirections <br>";<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<The above echo gives out the http://coers6000.sdstate.edu/~hoodad/Sitel..._updated_DB.phpyou can see the output at the above link
prathapml Posted September 12, 2005 Posted September 12, 2005 @devhooda:Please click the "reply" button to post something.The "report" button is *NOT* for posting, its for REPORTING wrong-doing by some other member, to the mods or admins.
dman Posted September 12, 2005 Posted September 12, 2005 (edited) No inconvenience, that's what MSFN is for! look at "source" in browser you will see you still have many blank spaces. It will wrap on the first one it Finds. try the php str_replace() function to convert all " " to you also should pad your individual data item strings to standard length so columns line up, else put them in a table.http://us2.php.net/manual/en/function.str-replace.php$htmlout = "1 0000-00-00 Missouri Bad Jackson 3.3113E+11 3208 4 S Fork Bad River ......."$htmlout = str_replace(" ", " ", $htmlout);echo $htmlout Edited September 12, 2005 by dman
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now