Debug Undefined index ban end php - debugging

I have 2 debug notices both this message below
[phpBB Debug] PHP Notice: in file [ROOT]/memberlist.php on line 428: Undefined index: ban_end
the line in question is
if ($member['ban_end'] >= time() || $member['ban_end'] == '0')
now if i add isset like this it kills 1 debug
if (isset($member['ban_end']) >= time() || $member['ban_end'] == '0')
how do i apply isset so both ban_end gets covered by isset

The code you post won't work since it's comparing the value of time() against a boolean.
You could do this:
if (isset($member['ban_end'])) {
if ($member['ban_end']) >= time() || $member['ban_end'] == '0') {
// some code
}
} else {
// do something if variable not set
}
You probably need to understand why the variable isn't set though, rather than applying a band-aid fix.

Related

How to return to beginning of program from inside of if statement?

I'm practicing some basic coding, I'm running a simple math program running in the terminal on Visual Studio Code.
How do I create an option to return to the beginning of the program, or exit the program after getting caught in an if statement?
Example:
#beginning of program
user_input=input('Please select "this" or "that": ')
findings=user_input
If findings == this:
print(this)
# How can I redirect back to first user input question, instead
# of just ending here?
if findings == that:
print (that)
# Again, How do I redirect back to first user input, instead of
# the program ending here?
# Can I setup a Play_again here with options to return to user_input,
# or exit program? And then have all other If statements
# redirect here after completion? How would I do that? with
# another If? or with a for loop?
#end program
You can try wrapping the whole program in a while loop like this:
while(True):
user_input=input('Please select "this" or "that": ')
this = 'foo'
if user_input == this:
print(this)
continue
if user_input == this:
print(this)
continue
Unfortunately, that 'another technique' I thought of using didn't work.
Here's the code (the first example modified):
import sys
def main():
# Lots of setup code here.
def start_over():
return #Do nothing and continue from the next line
condition = 1==1 #Just a sample condition, replace it with "check(condition)".
float_condition = condition
def play(*just_define:bool):
if not just_define:
play_again = input('play again? "y" or "n"')
if play_again == 'y':
start_over() #Jump to the beginning of the prohram.
if play_again == 'n':
sys.exit() #Exit the program
while True:
if float_condition == True:
# print(float_condition)
play() #skip to play_again from here?
if float_condition == False:
#print(float_condition)
play() #skip to play_again from here?
#I removed the extra "main()" which was here because it'd cause an infinite loop-like error.
main()
Output:
play again? "y" or "n"y
play again? "y" or "n"n
Process finished with exit code 0
The * in the play(*just_define:bool) function makes the just_define parameter optional. Use the parameter if you want to only tell Python to search for this function, so it doesn't throw a ReferenceError and not execute anything that's after the line if not just_define:. How to call like so: play(just_define=True).
I've used nested functions. I've defined play so that you can call it from other places in your code.
Thanks to #Hack3r - I was finally able to choose to return back to the beginning of the program or exit out. But it resulted in a new issue. Now my print(results) are printing 4 or 5 times...
Here is the actual code I built and am working with:
def main():
math_Options=['Addition +','Subtraction -','Multiplication *','Division /']
math_func=['+','-','*','/']
for options in math_Options:
print(options)
print('Lets do some Math! What math function would you like to use? ')
while True:
my_Math_Function = input('Please make your choice from list above using the function symbol: ')
my_Number1=input('Please select your first number: ')
x=float(my_Number1)
print('Your 1st # is: ', x)
my_Number2=input('Please select your Second Number: ')
y=float(my_Number2)
print('Your 2nd # is: ', y)
z=float()
print('')
for Math_function in math_func:
if my_Math_Function == math_func[0]:
z=x+y
if my_Math_Function == math_func[1]:
z=x-y
if my_Math_Function == math_func[2]:
z=x*y
if my_Math_Function == math_func[3]:
z=x/y
if (z % 2) == 0 and z>0:
print(z, ' Is an EVEN POSITIVE Number')
if (z % 2) == 1 and z>0:
print(z, ' IS a ODD POSTIVE Number')
if (z % 2) == 0 and z<0:
print(z, ' Is an EVEN NEGATIVE Number')
if (z % 2) ==1 and z<0:
print(z, ' IS a ODD NEGATIVE Number')
if z==0:
print(z, 'Is is Equal to Zero')
print('')
play_again=input('Would you like to play again? "y" or "n" ')
if play_again == 'y':
continue
if play_again == 'n':
break
main()
main()

codeigniter error:syntax error, unexpected '1' (T_LNUMBER)

ajax driven search(date range is input).
search is working properly however when I am trying to convert status(value 1 & 2 is stored in database) as ON or OFF. I'm getting this error, when I change if ('.$row->status.' === '1' ) to if ('.$row->status.' === 1 ) output is
if (1 === 1 ) else if (2 === 1 ) else if (1 === 1 ) else
foreach ($query as $row)
{
$output .= '
<tr>
if ('.$row->status.' === '1' ) //err
<td>ON</td>
else
<td>OFF</td>
</tr>
You have to go through something like the following thought process...
"I want to output a string "On" or "Off" based on the result of $row->status.
So first you need to determine what the string , let's call it $on_off.
Then you need to create your string segment based upon $on_off.
foreach ($query as $row)
{
// Determine the ON/OFF string to output
$on_off = ($row->status)?'ON':'OFF';
// Create the String Segment.
$output .= '<tr><td>';
$output .= $on_off;
$output .= '</td></tr>';
// Whatever else is here...
}
The reason I have broken $output into 3 commands is to help break up the table tags into something a bit more readable and less prone to mistakes.

Why isn't .replace working in Ruby Shoes?

I am programming a little game based on the Fate RPG. When the dice are rolled, I want to replace a string with another string using .replace. I can get it to work in an isolated environment, but when I try to call the function from inside my program; it is as if Shoes is completely unaware of it.
Here is a simple example of how the function works that is executing correctly:
Shoes.app {
#push = button "Push me"
#note = para "Nothing pushed so far"
#push.click { #note.replace "Aha! Click!" }
}
And here is the relevant code from my game:
$results = para "Roll results go here.", :align => "center",
:margin_bottom => 20, :margin_top => 8
#roll_button.click {
current_roll = Die.new
current_roll.roll
current_roll.display_dice
current_roll.tally
current_roll.calc_total_roll(1) #param = skill level
$shift = current_roll.calc_total_shift(2) #param = opposition
$results.replace "Actual results"
}
The $results block is in a different position in the code than the #roll_button.click block, but I have tries moving the click block to many different places in the code, and it didn't make a difference, so I don't think its relevant. Thanks.
*edit: Removed unnecessary '=' after $results.replace
I finally got it to work. The problem was the .display_dice function running just before .replace. The offending code is here:
if $result1 == 1
$die1.path = "dice_plus-1.png"
elsif $result1 == 0
$die1.path = "dice_nil-1.png"
elsif $result1 == -1
$die1.path = "dice_minus-1.png"
else
exit(1)
end
I intended the exit(1) to let me know if my dice were receiving values they shouldn't, but it somehow prevented the next line of code from running, even though the flow of the program avoided those lines. The fixed code is here:
if $result1 == 1
$die1.path = "dice_plus-1.png"
elsif $result1 == 0
$die1.path = "dice_nil-1.png"
else $result1 == -1
$die1.path = "dice_minus-1.png"
end
You're not calling a replace method, you're calling a replace= method which probably doesn't exist. Try it without the equals sign.

PHP preg_match unknown modifier error

Message: preg_match(): Unknown modifier 'p'
Filename: core/Router.php
Line Number: 399
Backtrace:
File: /home/spdcin/public_html/demo/no-waste/index.php
Line: 292
Function: require_once
iam getting this error on line 2
$key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key);
// Does the RegEx match?
//line no 2
if (preg_match('#^'.$key.'$#', $uri, $matches))
{
// Are we using callbacks to process back-references?
if ( ! is_string($val) && is_callable($val))
{
// Remove the original string from the matches array.
array_shift($matches);
// Execute the callback using the values in matches as its parameters.
$val = call_user_func_array($val, $matches);
}
// Are we using the default routing method for back-references?
elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)
{
$val = preg_replace('#^'.$key.'$#', $val, $uri);
}
$this->_set_request(explode('/', $val));
return;
}
}
There is a problem with your regex and PHP thinks you try to apply a 'p' modifier, which is not valid.
You will probably get to know what is wrong with your regex if you do :
echo '#^'.$key.'$#';
The fact that you try to program a router indicates that $key most probably contains '#p' (common in URLs).
Solution : In your case you can escape the character '#' with backslashes. Quoted from the php documentation :
"If the delimiter needs to be matched inside the pattern it must be escaped using a backslash."
If I understand your problem correctly, surround $key with preg_quote() like this:
if (preg_match('#^'.preg_quote($key).'$#', $uri, $matches))
This function will automatically escape ALL regex commands in $key.

Cronjob in Laravel 5

I have the job table contains post_at,day_open,block properties
The post_at property is the day when user post the job (Ex:2015-11-24)
The day_open property is the day that job is open (Ex:10)
The block property can contain 2 values 0 or 1. If post_at + day_open > right now the block value will change from 0 to 1
So how can I do that using cronjob?
First check wheather the post_at,day_open are edit in current date
$date = date('Y-m-d');
$job= DB::table('job') ->select('post_at','day_open','block')->where('updated_at',$date) -first();
$id=$job->id;
if(isset($job) && !empty($job))
{
$finding=CronJobCotroller::pushNotify($id);
}
if it's true it go to function pushNotify under the CronJobCotroller,here we write the coding for changing block field value 0 to 1.
public function pushNotify($id) {
$job= DB::table('job') ->select('block')->where('id',$id) ->get();
if(isset($job) && !empty($job))
{
foreach ($job as $cb)
{
$job= DB::table('job')->update('block',1)->where('block',0);
}
}
}

Resources