Jump to content

Concise Checking Of Field Values On Insert Query


chibineku
 Share

Recommended Posts

I am writing a script to add items to a shopping basket. My shopping basket table has fields for the userid, product id, session id, notes and a few others. Some of the fields can be blank. For example:if someone isn't signed in, then I will store their session id in the table and, if they sign in, add their userid so I have a permanant way to match the items in the table to the user. If they are, I'll add the userid. When it comes to the INSERT query, can I do something like this:$add_sql = "INSERT into sessionBasket (userid) VALUES ('". isset($_SESSION["userid"]) ? $_SESSION["userid"] : "" ."'";It would save me so much time on variable checking and branching because people could be signed in or not, items could have notes or not, that sort of thing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...