Well, Dan, not sure what you mean be a “create” and “update” page. But, normally, you handle sales carts as
a list of items linked to the one id for that cart. Each entry is one item row on the invoice. To display it for a
client, you need to loop thru the items and do other queries to retrieve the name of each item in the rows of
things they ordered. So, basically, you would use this same process for your selection of contacts. You need
to show the user only the text they need to see. You never show them id numbers as they change all of the
time and usually are not in any sort of order that makes sense to a user. (As you delete id’s in a database’s
table, they are eventually replaced with other entries and therefore are never shown to the user.) Normally,
you would sort a list by either by alpha or by date of creation. Depends on what you are doing…
Sorry if I got off track… So, if you save the id, name, etc into your database, it has already been checked for
security issues. Normally, every time you insert data into your database, you make sure it is safe before you
call the query to insert it. Therefore, you already know the data is safe. The id of a record is normally done by
the database engine as an “auto-increment INT” type of field. Therefore, it does not need “htmlspecialchars()”
function to check it’s safety. Most likely it is not needed for the name either as that is normally checked before
writing to the database.
I use id of the current user saved in a $_SESSION[] variable all the time. So, that part is good. Running a query
against the database to get a supplier’s name, or to load a long list of them to put into a SELECT clause does
not take much resource wise on the server. So, how you did it should word just fine. The only thing I see that
you might want to do is drop some of the extra echo’s you use to create the tags. It is faster to use
a concatenation “.” as needed. It is only a small amount, so not a big deal, but, why make the server work
more than it is needed. Something like this should work:
echo ‘’ . $r[‘name’] . ‘’;
You can also do it directly without the concatenation, although some like it spread out for ease of reading…
echo ‘<option value=$r[“id”]>$r[“name”]’;
Not sure if that was what you needed, but, hope it helps…
Ernie