![]() On the other hand, if the visitors submit the one that is filled with the value "Green", it shall insert the value "Green" into the database.In this comprehensive guide, we will explore the PHP `explode()` function in-depth, discussing its purpose, syntax, parameters, and numerous examples to help you understand and effectively use this function in your PHP projects. what more code you are expecting?Īmong the above forms if the visitors submit the blank one, it shall insert a predefined value (not available in database) into the database. My question is very simple & clear here and i already posted sufficient codes related to my question. " />įorm input value here not only pre-populate the value of variable in form form field but also it posts a predefined value of variable into the database.Īren't we always insert hidden value of a form input through the above syntax. If you are having a problem with inserting into the database you should really show the code that actually has to do with a database. It does not, in any way, have anything to do with a database. ![]() All this line does is pre-populate a form field with whatever the value is in the $var variable. This is what traq was trying to point out to you. if my syntax is correct now how should i define the conditional value based on explode function so that the value "No Color Chosen" is inserted into database if the visitors submit the blank form.Īctually no, nothing about that line has anything to do with a database. And that is ignoring the fact that you're operating under the (false, IMHO) assumption that no color names contain spaces (what happened to the colors "ruby red" or "robbin egg blue" ?).įinally, on to the matter of your question:Īre you asking how to define a variable based on user input, if it is set/nonempty, or a default value, if otherwise? Sounds like you just need a simple if /man statement that checks if a given external variable is empty /man. Thus, not only have you shown us code that won't parse, but you've also shown us code that makes no sense and contradicts itself. Which treats $colors as if it were a string. Which means $colors is an array, but then you later have this: GetSQLValueString(trim($colors), "text") For example, you've got this: $colors = explode (" ", $color) Ignoring that, there are more errors that further confuse the matter. Might want to clean up your code before posting it in the future if you expect it to help explain what it is you're wanting to do. How should i define the following value as conditional statement of form's text input value in this case so that the default value ( shall insert the default value "No Color Chosen") is inserted on blank form submission ?įor one, the PHP code you posted contains numerous parse errors. Header(sprintf("Location: %s", $insertGoTo)) " method="post" name="form1" id="form1"> $Result1 = mysql_query($insertSQL, $x) or die(mysql_error()) GetSQLValueString(trim($colors), "text"), $insertSQL = sprintf("INSERT INTO colortable (color_id, color_name) VALUES (%s, %s)", ![]() I came up with the following syntax if ((isset($_POST)) & ($_POST = "form1")) )" How can i insert a default value (For example, "No Color Chosen" is default value here) using explode function if the users submit the blank form when i don't want to prevent users from submitting the blank form. The following form collects data about the color preference of the visitors. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |