Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've probably miss something but I realy don't understand that :
if(trim($_GET[$slug]) == trim($cat->$slug)) {
$selected = 'selected';
}
else {
$selected = '';
}
var_dump(trim($_GET[$slug]));
var_dump(trim($cat->slug));
var_dump($selected);
Show :
string(8) "albanais"
string(8) "albanais"
string(0) ""
Should be using $cat->slug inside the if statement rather than $cat->$slug
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I have to make a regex for a password with the following conditions:
- minimum 4 characters
- at least 1 non-word character.
I tried this way:
$regex_password = '#(\W)+#';
$regex_password1 = '#(?i)([a-z\d])+#';
if ((!preg_match($regex_password, trim($_POST['pass']))) && (!preg_match($regex_password1, trim($_POST['pass']))) && strlen(trim($_POST['pass'])) <5){
//error
}
And then tried to create a new account with the password: "pas" and it's working, so there's something wrong with my regex. Can someone help?
You just have to change your && to || i.e. if any of condition false then it will echo an error
if ((!preg_match($regex_password, trim($_POST['pass']))) || (!preg_match($regex_password1, trim($_POST['pass']))) || strlen(trim($_POST['pass'])) <5){
echo "error";
}
else
{
echo "ok";
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm doing some PHP traning, and wanted to make my own copy of "Rock, Paper and Scissors" and then I'd like to compare the results from the user and the computer, and I tried with this code:"
if($choice = 'Rock' and $pcSelect == 'Scissors'){
echo "You win!";
}
Plz help me,
Magn0053
You are assigning 'Rock' to $choice with =. You need to test equality with == like in the second conditional.
Use && instead of and in your if
if($choice == 'Rock' && $pcSelect == 'Scissors'){
echo "You win!";
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Okay this really strange or I am missing something. When I run this very simmple PHP script on cmd I get the expected output which is 0. but when I uncomment the last two lines of code. . .nothing is displayed.
<?php
$test1 = 0;
echo $test1;
$test2 = 0;
#$test1_weight = 0:
#$test2_weight = 0;
?>
Is there some rule against declaring variables after an echo statement?
$test1_weight = 0:
--> change ":" to ";"
No there is no rule against declaring variables after an echo statement
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am validating a condition for
$time = $user['time_send'];
$chk_date = date('Y-m-d H:i');
var_dump($time == $chk_date);
But I am getting bool(false) as output.
$time = '2014-03-7 15:14';
$chk_date = '2014-03-07 15:14';
if(strtotime($time) == strtotime($chk_date)){
echo 'hola';
}else{
echo 'hello';
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
<?php
$datetime=date("d-m-y");
$date1=date("d")+1;
$datetime1=date("$date1-m-y ");
$date1=$date1+1;
$datetime2=date("$date1-m-y ");
$date1=$date1+1;
$datetime3=date("$date1-m-y ");
echo $_POST['date1'];
echo $datetime1;
if($_POST['date1']==$datetime1)
{
header("location:bus2.php");
}
?>
here if condition doesn't work even though echo $_POST['date1']; and echo $datetime1; shows the same result.
The values are NOT the same:
$datetime1=date("$date1-m-y ");
^--this space makes all the difference:
$_POST['date1'] = '14-02-2014';
$datetime1 = '14-02-2014 ';
^--- spot the difference