in php what is the function of populate_select()?
in php what is the function of populate_select()?
Sorry, but we're going to need more information than that to help you, there is no inbuilt function in php called populate_select(), so are you referring to a user defined function?
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
Anime Views Forums
Bernie
That expression is like thatCode:<?php populate_select("countries","countryid","country",$education->countryid); ?>
Last edited by keyboard; 10-12-2012 at 12:08 AM. Reason: Format: Code Tags
I double checked the list of inbuilt functions, there is no function called populate_select, the function must be user defined, so we'll only be able to help you if we have the code for the function.
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
Anime Views Forums
Bernie
yes i found that user defined function which is like
Code:<?php function populate_select($table,$fields_id,$fields_value,$selected){ $conn=db_connect(HOST,USER,PASS,DB,PORT); $sql="Select $fields_id,$fields_value From $table Order By $fields_value"; $results=query($sql,$conn); while ($row = fetch_object($results)){ $SelectedField=($row->$fields_id==$selected) ? " selected" : ""; echo "<option value='" . $row->$fields_id ."'". $SelectedField . ">" . $row->$fields_value . "</option>"; } free_result($results); } ?>
Last edited by keyboard; 10-12-2012 at 12:09 AM. Reason: Format: Code Tags
It selects some info from a DB and displays it. It's not very well-written, however. If you need to do this, I'd recommend a different method.
^ more specifically than that, It populates a <select> tag (drop down options)
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
Anime Views Forums
Bernie
it's intended to, yes.
some specific downfalls this function has:
1. creates a new DB connection for *every* use
2. does not validate or sanitize data used in the query
......(I don't know how data is passed to the function, but if it comes from the user, this is a serious problem)
3. doesn't check if there was an error, or if any results were actually returned
4. outputs a load of un-escaped HTML (of unknown size) right in the middle of the function
......what happens if there's a<or"(or worse yet, a whole <tag>) in the results?
......what happens if there's a script error later on?
......what happens if there's no opening/closing<select>tag outside this function?
Bookmarks