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
im trying to make something to change password.
nkode is the new password
gkode is the old password
if($_GET[rediger] == 'ja'){
$nkode = md5($_POST[nkode]);
$gkode = md5($_POST[gkode]);
if($nkode !== ''){
if($gkode !== ''){
$nukode = $udskrivprofil[Kodeord];
if($gkode == '$nukode'){
echo "success";
} else {
echo "fail";
}
}
}
echo "<br>$gkode <br> $nukode";
}
both $gkode and $nukode outputs the 100% same, yet i get the fail error... whats wrong?
if($gkode == '$nukode'){
Look at those quotes. You're comparing the contents of $gkode against a string which has the characters $, n, u, etc... in it...
Maybe you wanted
if($gkode == $nukode){
instead?
remove quotes from $nukode variable...
if($_GET[rediger] == 'ja'){
$nkode = md5($_POST['nkode']);
$gkode = md5($_POST['gkode']);
if($nkode !== ''){
if($gkode !== ''){
$nukode = $udskrivprofil[Kodeord];
if($gkode == $nukode){
echo "success";
} else {
echo "fail";
}
}
}
echo "<br>$gkode <br> $nukode";
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
If the phone number matches , I am able to print "Yes". If it doesnot match , i need to print "No". But if i include else part , its executing only else part. Please guide me how and where to write else part.
<?php if($re['phone_v'] == "1"){
echo "Yes";
}else if($re['phone_v'] == "0"){
for($i=0;$i < count($crusers);$i++) {
if ($re['phone'] == $crusers[$i]['phone']) {
echo "Yes";
}
}
}
?>
I am checking condition inside table in view. small thing is making complicated.
This will help you.
$re['phone_v'] = 0;
$re['phone'] = 1;
$crusers[0]['phone'] = 1;
if($re['phone_v'] == "1"){
echo "Yes";
}else{
if($re['phone_v'] == "0")
{
for($i=0;$i < count($crusers);$i++)
{
if ($re['phone'] == $crusers[$i]['phone'])
{
echo "Yes11";
}else{
echo "No";
}
}
}
}
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 4 years ago.
Improve this question
I have the following code, but I have no idea what I'm doing wrong. Any idea how to fix this?
<?php
if($testing = series_get_meta('code_name')) {
if ($testing == 'Pre1';) {
echo "Pre1";
} elseif ($testing == 'Gem2';) {
echo "Gem2";
} elseif ($testing == 'Remi1';) {
echo "Remi1";
} else {
echo "Default";
}
}
?>
You have a couple typos.
Don't use semi colons in the () of your if/else statements.
You have an extra parenthesis at the end of your last else statement.
Like so:
if ($testing == 'Pre1')
{
echo "Pre1";
} elseif ($testing == 'Gem2') {
echo "Gem2";
} elseif ($testing == 'Remi1') {
echo "Remi1";
} else {
echo "Default";
}
However you task is probably better suited to using a switch() statement like so:
switch ($testing) {
case 'Pre1':
echo 'Pre1';
break;
case 'Gem2':
echo 'Gem2';
break;
case 'Remi1':
echo 'Remi1';
break;
default:
echo 'Default';
}
Hey you have added semicolon inside the if condition, just remove that
<empty>
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I need to make a conditional statement where the 5 variables should be empty before perform an action. The problem is some variables can be zero, false or NULL value. How to catch all of them?
Which one is better?
If (!$a && !$b && !$c && !$d && !$e) {
// do some action
} else {
exit;
}
OR
If (empty($a) && empty($b) && empty($c) && empty($d) && empty($e)) {
// do some action
} else {
exit;
}
Thank you.
First of all, use "code sample" to show code.
When you use !$a you are actually casting $a to boolean.
The problem here is
$a = 0;
if (!$a) {
echo 'NOT EMPTY';
} else {
echo 'EMPTY';
}
//OUTPUT EMPTY BECAUSE 0 to boolean is FALSE
Same example with NULL value.
About empty i advice you to check the documentation
Read it and choose the way that fit your needs.
Hope this helps
This could be an approach to check multiple variables are empty at once.
<?php
$a = $b = $c = $d = $e = '';
#$b = 5; // comment out to go on else block
if (empty($a . $b . $c . $d . $e)){
echo "All variables are empty, do what you want to do man";
}else{
echo "One of variable is not empty";
}
?>
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 7 years ago.
Improve this question
Well, I have the problem narrowed down to one group of code, and here it is:
<?php
if( isset($_POST['submit'])){
**if($_POST['shortsitename'] == ""){$newshortsitename = $shortsitename;}else{ $newshortsitename = $_POST['shortsitename'];}
if($_POST['organization'] == ""){$neworganization = $organization;}else{$neworganization = $_POST['organization'];}
if($_POST['city'] == ""){$newcity = $city;}else{$newcity = $_POST['city'];}
if($_POST['state'] == ""){$newstate = $state;}else{$newstate = $_POST['state'];}**
$user_lvl = \Fr\LS::getUser("user_lvl");
$updateGroup = \Fr\LS::updateGroupinfo(
array(
"shortsitename" => $newshortsitename,
"organization" => $neworganization,
"city" => $newcity,
"state" => $newstate
), $user_lvl
);
if($updateGroup === "success"){
echo "<label>Success.</label>";
}elseif($updateGroup === false){
echo "<label>Update failed.";
}
?>
Basicly, I have a form that lets user change the information about their organization in a database. However, when I have this code in the site, it returns internal server error 500. When I removed this block of code, the site displays fine. My main question is, is the code that is bolded correct, or did I miss word it?
**Edit: It's not letting me bold the code, but there are "stars" around the code I am talking about.
Your Update failed <label> tag does not have a closing </label> and I think you are missing 2 } on the end. Is $shortsitename defined above?
<?php
if( isset($_POST['submit'])){
//**
if($_POST['shortsitename'] == ""){
$newshortsitename = $shortsitename;
}else{
$newshortsitename = $_POST['shortsitename'];
}
if($_POST['organization'] == ""){
$neworganization = $organization;
}else{
$neworganization = $_POST['organization'];
}
if($_POST['city'] == ""){
$newcity = $city;
}else{
$newcity = $_POST['city'];
}
if($_POST['state'] == ""){
$newstate = $state;}else{
$newstate = $_POST['state'];
}
//**
$user_lvl = \Fr\LS::getUser("user_lvl");
$updateGroup = \Fr\LS::updateGroupinfo(
array(
"shortsitename" => $newshortsitename,
"organization" => $neworganization,
"city" => $newcity,
"state" => $newstate
), $user_lvl
);
if($updateGroup === "success"){
echo "<label>Success.</label>";
}elseif($updateGroup === false){
echo "<label>Update failed.";
}
?>
Above is reformatted version of your code.
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
Im working on a simple roll a dice program. So it has to generate a random number from 0-5 and when it selects 0-4 it echo's and when it selects 5 it echo's.
To it keeps echo the first echo 'you got 6'. I cant seem to get my mind around this.
<!DOCTYPE html>
<html>
<head>
<title>A loop of your own</title>
<link type='text/css' rel='stylesheet' href='style.css'/>
</head>
<body>
<?php
$trows = 0;
$dice = 0;
while ($dice == 0)
{
$dice = rand(0,5);
$trows++;
}
if ($dice = 5)
{
echo 'you got 6';
}
else
{
echo 'you got 1-5';
}
echo '<br><br>';
echo $trows;
?>
</body>
if ($dice = 5)
Is actually assigning the value of 5 to dice, rather than comparing the values, so the first part of the if statement will be entered, rather than the else.
if ($dice == 5)
is what you are looking for
Edit: From your comments I think this is what you are looking for
$trows = 0;
$dice = 0;
while ($dice != 5)
{
$dice = rand(0,5);
$trows++;
if ($dice == 5) {
echo 'you got 6';
} else {
echo 'you got 1-5';
}
echo '<br><br>';
echo $trows;
}
Your if statement is not testing for a condition, but rather performing an assignment and then evaluating the truth of that assignment (which will always be true in this case).
Your code should be:
if($dice == 5)
{
echo 'you got 1-5';
}
Notice the == instead of the single =
This will do the trick
while ($trows == 0)
{
$dice = rand(0,5);
if ($dice == 5)
{
echo 'you got 6';
}
else
{
echo 'you got 1-5';
$trows++;
}
}