Search the Community
Showing results for tags 'null'.
-
Hello! Please explain to me how gender validations from scripts 2.3 differ from the nested one in script 2.4. I have this in 2.3 (updated with NULL coalescing operator while practicing Pursue section): $gender = $_REQUEST['gender'] ?? NULL; if ($gender == 'M') { $greeting = '<p><strong>Good day, Sir!</strong></p>'; } elseif ($gender == 'F') { $greeting == '<p><strong>Good day, Madam!</strong></p>'; } else { $gender = NULL; echo '<p class="error">Gender must be either "M" or "F"!</p>'; /* You may wonder how this last case may be possible, considering the values are set in the HTML form. If a malicious user creates their own form that gets submitted to your handle_form.php script (which is very easy to do), they could give $_REQUEST[‘gender’] any value they want. */ } and this in 2.4: if (isset($_REQUEST['gender'])) { $gender = $_REQUEST['gender']; if ($gender = 'M') { $greeting = '<p><strong>Good day, Sir!</strong></p>'; } elseif ($gender = 'F') { $greeting = '<p><strong>Good day, Madam!</strong></p>'; } else { $gender = NULL; echo '<p class="error">Gender must be either "M" or "F"!</p>'; /* You may wonder how this last case may be possible, considering the values are set in the HTML form. If a malicious user creates their own form that gets submitted to your handle_form.php script (which is very easy to do), they could give $_REQUEST[‘gender’] any value they want. */ } } else { // $_REQUEST['gender'] is not set. $gender = NULL; echo '<p class="error">You forgot to select your gender!</p>'; } It seems that these scripts do the same job, or I just can't figure out the difference, please help me to understand it. And also I want to if we could use NULL coalescing operator in script 2.4 some way. Thank you!
- 1 reply
-
- nested
- null coalescing operator
- (and 6 more)
-
Is is possible to Insert a NULL value into a table by assigning it to a variable. For a low level user I want the activated column to have the following inserted: $a = md5( uniqid( rand(), true ) ); // put 32 char code into column "activated" for email verification But for a higher level user, I don't want them to have to verify their email address. So I thought I could set $a = "NULL" or $a= NULL I only end up with the word NULL instead a real null . I also thought there might be away of setting the column to default to NULL. Then the md5 () would write over it and that would solve the problem. But I couldn't do that either. Now I just have two separate INSERT queries under a conditional with a "SET activated=NULL" for one of them. It works, but I hate writing the code twice. thanks, chop
-
I have an images table that has 5 foreign keys that reference 5 other tables, each of those tables uses the images table to store images, when an image gets uploaded, the foreign key in question gets a value associated with it in the images table but the other 4 foreign keys will get NULL values in that row. Is that acceptable, or should I rethink my database design? What would be the best way to go?
-
Hi, I have a question about Creating Modal Windows example... Quote: If I remove the following lines (altogether, all three lines): In function openModal(): document.getElementById('openModal').onclick = null; In function closeModal(): document.getElementById('openModal').onclick = openModal; In function closeModal(): document.getElementById('closeModal').onclick = null; so that the new code looks like this: everything works well, there are no errors. I don't understand why there are these three lines? Thank you in advance!
- 2 replies
-
- javascript
- modal
-
(and 2 more)
Tagged with:
-
Have a select situated like so: $number = range(0,5); <select name="amount"> foreach ($number as $key => $value) { echo '<option value="' . $key . '">' . $value . '</option>'; } </select> The handling script contains: if (!empty($_POST['amount'])) { $a = mysqli_real_escape_string($dbc, $_POST['amount']); $b = (integer)$a; } else { $b = false; } It works swimmingly enough, until a '0' $key-value buggers the handling script. The script swears on a stack of manuals it's being fed something other than the integer 'zero'. How does one get '0' (zero) to be - and stay as- the *number* zero, and not a NULL or FALSE, etc. ~ David