isset
PHP shorthand for isset()? [duplicate]
Update for PHP 7 (thanks shock_gone_wild) PHP 7 introduces the null coalescing operator which simplifies the below statements to: $var = $var ?? “default”; Before PHP 7 No, there is no special operator or special syntax for this. However, you could use the ternary operator: $var = isset($var) ? $var : “default”; Or like this: … Read more
What is the difference between null and empty?
A variable is NULL if it has no value, and points to nowhere in memory. empty() is more a literal meaning of empty, e.g. the string “” is empty, but is not NULL. The following things are considered to be empty: “” (an empty string) 0 (0 as an integer) 0.0 (0 as a float) … Read more
Check if value isset and null
IIRC, you can use get_defined_vars() for this: $foo = NULL; $vars = get_defined_vars(); if (array_key_exists(‘bar’, $vars)) {}; // Should evaluate to FALSE if (array_key_exists(‘foo’, $vars)) {}; // Should evaluate to TRUE
PHP: Check if variable exist but also if has a value equal to something
Sadly that’s the only way to do it. But there are approaches for dealing with larger arrays. For instance something like this: $required = array(‘myvar’, ‘foo’, ‘bar’, ‘baz’); $missing = array_diff($required, array_keys($_GET)); The variable $missing now contains a list of values that are required, but missing from the $_GET array. You can use the $missing … Read more
What is the PHP shorthand for: print var if var exist
For PHP >= 7.0: As of PHP 7 you can use the null-coalesce operator: $user = $_GET[‘user’] ?? ‘guest’; Or in your usage: <?= $myVar ?? ” ?> For PHP >= 5.x: My recommendation would be to create a issetor function: function issetor(&$var, $default = null) { return isset($var) ? $var : $default; } This … Read more
Calling a particular PHP function on form submit
In the following line <form method=”post” action=”display()”> the action should be the name of your script and you should call the function, Something like this <form method=”post” action=”yourFileName.php”> <input type=”text” name=”studentname”> <input type=”submit” value=”click” name=”submit”> <!– assign a name for the button –> </form> <?php function display() { echo “hello “.$_POST[“studentname”]; } if(isset($_POST[‘submit’])) { display(); … Read more
PHP Error : Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` [duplicate]
You need to add parentheses around your code: Before: $reference->frotel_vitrine = empty($item->special) ? null : $item->special == 2 || $item->special == 3 ? ‘active’ : ‘deactivate’; After : $reference->frotel_vitrine = empty($item->special) ? null : (($item->special == 2 || $item->special == 3 )? ‘active’ : ‘deactivate’); That should solve the issue.
Using if(isset($_POST[‘submit’])) to not display echo when script is open is not working
You need to give your submit <input> a name or it won’t be available using $_POST[‘submit’]: <p><input type=”submit” value=”Submit” name=”submit” /></p>
Delete multiple rows by selecting checkboxes using PHP
You should treat it as an array like this, <input name=”checkbox[]” type=”checkbox” value=”<?php echo $row[‘link_id’]; ?>”> Then only, you can take its count and loop it for deletion. You also need to pass the database connection to the query. $result = mysqli_query($dbc, $sql); Yours did not include it: $result = mysqli_query($sql);