ilikephp Posted January 22, 2011 Share Posted January 22, 2011 Hi, I am trying to call the data from Mysql but I am getting an empty drop down list, this is the code: mysql: create table years ( yearID integer auto_increment, year varchar(30), primary key (yearID) ); insert into years (yearID, year) values ('1', '2007-2008'); insert into years (yearID, year) values ('2', '2008-2009'); insert into years (yearID, year) values ('3', '2009-2010'); insert into years (yearID, year) values ('4', '2010-2011'); insert into years (yearID, year) values ('5', '2011-2012'); insert into years (yearID, year) values ('6', '2012-2013'); PHP: <?php require_once('../Connections/connection.php'); ?> <?php $result = @mysql_query( "select yearID, year, from sss.years"); print "<p>Select a year:\n"; print "<select name=\"yearID\">\n"; while ($row = mysql_fetch_assoc($result)){ $yearID = $row[ 'yearID' ]; $year = $row[ 'year' ]; print "<option value=$yearID>$year\n"; } print "</select>\n"; print "</p>\n"; ?> Thank you! Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 Remove the error suppression and you might actually see an error message. Better, yet, check for one. <?php require_once('../Connections/connection.php'); ?> <?php if ($result = mysql_query( "select yearID, year, from sss.years")) { if (mysql_num_rpws($result)) { print "<p>Select a year:\n"; print "<select name=\"yearID\">\n"; while ($row = mysql_fetch_assoc($result)) { $yearID = $row[ 'yearID' ]; $year = $row[ 'year' ]; print "<option value=$yearID>$year\n"; } print "</select>\n"; print "</p>\n"; } else { // no record found. } } else { trigger_error(mysql_error()); } Quote Link to comment Share on other sites More sharing options...
ilikephp Posted January 22, 2011 Author Share Posted January 22, 2011 thx for your help! I am getting this error: Notice: 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 'from sss.years' at line 1 Quote Link to comment Share on other sites More sharing options...
eevan79 Posted January 22, 2011 Share Posted January 22, 2011 $result = mysql_query( "select yearID, year from sss.years") Quote Link to comment Share on other sites More sharing options...
ilikephp Posted January 22, 2011 Author Share Posted January 22, 2011 I am using the code below, it is working fine, but how can I add to the first line of the list an item without a value like: "Select please" <?php $query="SELECT yearID,year FROM years"; $result = mysql_query ($query); echo "<select name=education_level value=''>Education Level</option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[yearID]>$nt[year]</option>"; } echo "</select>"; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 So, you have chosen to simply ignore the handling of errors like I showed you? Quote Link to comment Share on other sites More sharing options...
ilikephp Posted January 22, 2011 Author Share Posted January 22, 2011 For sure not but I did not understand it :S Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 Its simply checking to make sure the called functions actually work before using there results in another function. As for you question. Just change.... echo "<select name=education_level value=''>Education Level</option>"; to.... echo "<select name=education_level value=''>Education Level</option>"; echo "<option value=''>Select PLease</option>"; Quote Link to comment Share on other sites More sharing options...
ilikephp Posted January 22, 2011 Author Share Posted January 22, 2011 THANKS A LOT (Y) still have one issue: when the form is submitted successfully the success.php page will open $insertGoTo = "success.php"; if someone tries to put this link www.mywebsite.php/success.php it will be opened, how can I restricted from being viewed unless the form is submitted? Thanks, Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 If you are redirecting them to the success page there isn't much you can do. You could store a flag in the $_SESSION array but it seems like a bit of overkill to me. Quote Link to comment Share on other sites More sharing options...
ilikephp Posted January 22, 2011 Author Share Posted January 22, 2011 is there a tutorial about this? Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2011 Share Posted January 22, 2011 I wouldn't know. Quote Link to comment 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.