Jump to content

If not working


ecabrera

Recommended Posts

help why does the IF not work

 

if if($left && $right)

 

<?php  
if(isset($_POST['savebtn'])){

$left = $_POST['left'];
$right = $_POST['right'];

if($left && $right){

echo "there is text";

}else{
echo "this is no text";
}

}
?>

<div class="fullpage">
<form action="edithome.php" method="post">
<div class='left'>
<textarea name="left" style="width: 530px; height: 100%;">

</textarea>
</div>
<div class="right">
<textarea name="right" style="width: 420px; height: 100%;">

</textarea>
</div>
<input type="submit" name="savebtn" value"Save" />
</from>

</div>

Link to comment
Share on other sites

Not working "how"? what is the input and the output you feel is wrong. That condition is very "loose" meaning that as long as the variable is set and not an empty string it will result in true. Your textareas have a line break in them so it will always result in true unless the user removes the value. You should probably trim the value and then check if it is empty()

 

if(isset($_POST['savebtn']))
{
    $left = trim($_POST['left']);
    $right = trim($_POST['right']);

    if(!empty($left) && !empty($right))
    {
        echo "there is text";
    }else{
        echo "this is no text";
    }
}

Link to comment
Share on other sites

Thanks, but I know what it does.

 

Psycho posted at the same time I did.

 

Perhaps you need to turn on warning when others have replied while you were.

 

If you know what it does, why did you suggest it as a solution? Adding (!)empty() will not change the results he gets. A variable containing a line break will result in empty() returning FALSE.

Link to comment
Share on other sites

so empty() won't work for this.

 

Yes, I see that now. I didn't notice the scroll bar on his post earlier, so I didn't see the line break in the form.

 

Thanks, but I know what it does.

 

Psycho posted at the same time I did.

 

If you know what it does, why did you suggest it as a solution? Adding (!)empty() will not change the results he gets. A variable containing a line break will result in empty() returning FALSE.

 

See above.

 

I'm tired, and had a long day. I don't put in a lot of effort to people that don't put any effort in on their part. My apologies.

 

Stop busting my balls. :(

Link to comment
Share on other sites

This is a possible way to test emptiness (this may not help in finding a solution to the current problem, but we were talking about the empty() function, so I thought I would post it.)

 

Removes spaces/tabs/newlines/carriage returns (more might need to be removed):

<?php
function blank($str){
$newstr = preg_replace("/ |\r|\n|\t/", "", $str);
if(empty($newstr))
	return true;
return false;
}

if(blank($_POST['something']))
echo "post value is blank.";
else
echo "post value is not blank.";
?>

Link to comment
Share on other sites

well im not to advance like you guys but heres what i did and its working i dont if its the best way but hey i aleast im trying

 

<?php  

require "scripts/connect.php";

if(isset($_POST['savebtn'])){

$left = mysql_real_escape_string($_POST['left']);
$right = mysql_real_escape_string($_POST['right']);

if($left){
if($right){

$query = mysql_query("UPDATE `home` SET `left`='$left',`right`='$right' ");
$msg = "SAVED";

}else
    $msg = "Fill in";
}else
    $msg = "Fill in";
}
mysql_close();
?>
<?php
require "scripts/connect.php";

$mysql = mysql_query("SELECT * FROM home");
$rows = mysql_fetch_assoc($mysql);

$left = $rows['left'];
$right = $rows['right'];

mysql_close();
?>
<div class="fullpage">

<?php echo $msg; ?>

<form action="edithome.php" method="post">
<div class='left'>
<textarea name="left" style="width: 530px; height: 100%;">
<?php echo $left; ?>
</textarea>
</div>
<div class="right">
<textarea name="right" style="width: 420px; height: 100%;">
<?php echo $right; ?>
</textarea>
</div>
<input type="submit" name="savebtn" value"Save" />
</from>

</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.